|
联接数据库时出现的问题,初学,请多关照 。
[flamingo@luoshuiq Code]$gcc -o Expr7 -I/usr/include/pgsql Expr7.c -lpq
[flamingo@luoshuiq Code]$ ./Expr7
Connection to host=localhost dbname=template1 failed,could not connect to server: Connection refused
Is the server running on host localhost and accepting
TCP/IP connections on port 5432?
-------程序源码------------------------------------------------------------------------------
#include <stdlib.h>
#include <stdio.h>
#include <libpq-fe.h>
int main()
{
PGconn *conn ;
const char *connection_str = "host=localhost dbname=template1" ;
conn = PQconnectdb( connection_str );
if( PQstatus(conn) == CONNECTION_BAD )
fprintf( stderr,"Connection to %s failed,%s",connection_str, PQerrorMessage(conn) );
else
printf("Connected OK \n" );
PQfinish( conn );
return EXIT_SUCCESS ;
}
------------------------------------------------------------------------------------------- |
|