July 2005
Intermediate to advanced
1032 pages
27h 10m
English
Connecting to a database using libpgeasy is simple. libpgeasy provides a single connection function:
PGconn * connectdb( char * options );
The single argument to connectdb() is a connection string in the same form expected by the libpq PQconnectdb() function. An example connection string might look like this:
char * connectString = "dbname=movies user=sheila";
Let's look at a simple client that uses the connectdb() function:
/* client1.c */
#include <stdlib.h>
#include <libpq-fe.h>
#include <libpgeasy.h>
int main( int argc, char * argv[] )
{
connectdb( argv[1] ? argv[1] : "" );
disconnectdb();
exit( EXIT_SUCCESS );
}
You can use the following makefile to compile and link all samples in this chapter (see ...
Read now
Unlock full access