libpqxx

Error when connecting to Postgres database in C - using libpq-fe.h

北慕城南 提交于 2019-11-30 10:03:13
问题 Hey I am trying to connect to a database using postgres #include <stdio.h> #include <stdlib.h> #include <libpq-fe.h> int main(int argc, char* argv[]) { //Start connection PGconn* connection = PQconnectdb("host=webcourse.cs.nuim.ie dbname=cs621 sslmode=require user=ggales password=1234"); if (PQstatus(connection) ==CONNECTION_BAD) { printf("Connection error\n"); PQfinish(connection); return -1; //Execution of the program will stop here } printf("Connection ok\n"); //End connection PQfinish