Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- #include <postgresql/libpq-fe.h>
- #include <postgresql/9.5/server/postgres.h>
- struct DbConfig {
- char host[30];
- char dbName[30];
- char userName[30];
- char password[30];
- }
- int main(int argc, char *argv[]) {
- struct DbConfig dbConfig;
- dbConfig.host = "host";
- dbConfig.dbName = "db_name";
- dbConfig.userName = "user_name";
- dbConfig.password = "password";
- PGconn *con;
- PGresult *res;
- con = PQsetdb(
- dbConfig.host,
- "",
- NULL,
- NULL,
- dbConfig.userName,
- dbConfig.password);
- if (PQstatus(con) == CONNECTION_BAD) exit(1);
- res = PQexec(con, "select 1");
- PQclear(res);
- return 0;
- }
Add Comment
Please, Sign In to add comment