#include <libpq-fe.h>
#include <stdio.h>

static void exit_nicely(PGconn *conn)	{
	PQfinish(conn);
    	exit(1);
}

int main()	{
	char *conninfo = "<connection string>";
    	PGconn *conn = NULL;
    	PGresult *res = NULL;
	PGconn *conn2 = NULL;
    	PGresult *res2 = NULL;
	int i, j;
	int nFields;
	int lengths[4] = {5, 5, 9, 9};
	char *values[4] = {"james", "james", "jamessite", "jamessite"};
	int formats[4] = {0, 0, 0, 0};
	
	
	/* Make a connection to the database */
    	conn = PQconnectdb(conninfo);
    	if(PQstatus(conn) != CONNECTION_OK)	{
    		printf("Connection to database '%s' failed.\n", PQdb(conn));
        	printf("%s", PQerrorMessage(conn));
        	exit_nicely(conn);
    	}
    	PQfinish(conn);
	
	/* Make a connection to the database */
    	conn2 = PQconnectdb(conninfo);
    	if(PQstatus(conn2) != CONNECTION_OK)	{
    		printf("Connection to database '%s' failed.\n", PQdb(conn2));
        	printf("%s", PQerrorMessage(conn2));
       		exit_nicely(conn2);
    	}
    	PQfinish(conn2);

	return 0;
}
