pg.ddx.io  pgsql-students@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Using C++ to access Postgresql database
2+ messages / 2 participants
[nested] [flat]

* Using C++ to access Postgresql database
@ 2014-02-03 19:04  Madhurima Das <madhurima.das@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Madhurima Das @ 2014-02-03 19:04 UTC (permalink / raw)
  To: pgsql-students

Hi,

I am a beginner in Postgresql and trying to write a C++ program to connect
a database and retrieve information from a database.

I have downloaded Postgresql 9.3 in my MAC laptop and could create a
database XXX with a user YYY and password ZZZ. I can create, modify etc
using the pgAdmin3 tool.

Next, I tried connecting the database using a sample code:

#include <iostream>
#include <pqxx/pqxx>

using namespace std;
using namespace pqxx;

int main(int argc, char* argv[])
{
   try{
      connection C("dbname=XXX user=YYY password=ZZZ \
      hostaddr=127.0.0.1 port=5432");
      if (C.is_open()) {
         cout << "Opened database successfully: " << C.dbname() << endl;
      } else {
         cout << "Can't open database" << endl;
         return 1;
      }
      C.disconnect ();
   }catch (const std::exception &e){
      cerr << e.what() << std::endl;
      return 1;
   }
}

However, the output says: error: pqxx/pqxx: No such file or directory

When I try to install pqxx, I get configure error as:
PostgreSQL configuration script pg_config not found.  Make sure this is in
your
command path before configuring.  Without it, the configure script has no
way to
find the right location for the libpq library and its headers.

I am unable to find this file. The path of my Postgresql is
$ ps auxw | grep postgres | grep -- -D
postgres    70   0.0  0.0  2594280    444   ??  Ss    9:17AM   0:00.11
/Library/PostgreSQL/9.3/bin/postmaster -D/Library/PostgreSQL/9.3/data

I would appreciate your help in solving my problem.

Thanks for your patience!!

Regards
Madhurima

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Using C++ to access Postgresql database
@ 2014-02-03 19:06  Josh Berkus <josh@agliodbs.com>
  parent: Madhurima Das <madhurima.das@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Josh Berkus @ 2014-02-03 19:06 UTC (permalink / raw)
  To: pgsql-students


> I am unable to find this file. The path of my Postgresql is
> $ ps auxw | grep postgres | grep -- -D
> postgres    70   0.0  0.0  2594280    444   ??  Ss    9:17AM   0:00.11
> /Library/PostgreSQL/9.3/bin/postmaster -D/Library/PostgreSQL/9.3/data

pg_config should be in that same bin/ directory.  It's not?

-- 
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com


-- 
Sent via pgsql-students mailing list (pgsql-students@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-students



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2014-02-03 19:06 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-02-03 19:04 Using C++ to access Postgresql database Madhurima Das <madhurima.das@gmail.com>
2014-02-03 19:06 ` Josh Berkus <josh@agliodbs.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox