运行结果:
[fuyong@fuyong fuyong]$ ./shiyan
connection to host=127.0.0.1 dbname=template1 failed,could not connect to server: Connection refused
Is the server running on host 127.0.0.1 and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host 127.0.0.1 and accepting
TCP/IP connections on port 5432?
源代码:
#include<stdlib.h>
#include<stdio.h>
#include<libpq-fe.h>
int main()
{
PGconn *conn;
char*badmessage;
const char *connection_str = "host=127.0.0.1 dbname=template1";
conn=PQconnectdb(connection_str);
if(PQstatus(conn)==CONNECTION_BAD){
badmessage=PQerrorMessage(conn);
fprintf(stderr,"connection to %s failed,%s",connection_str,PQerrorMessage(conn));
printf("%s",badmessage);
}else {
printf("connected ok\n");
}
PQfinish(conn);
return EXIT_SUCCESS;
麻烦看看....~~~ |