Guest User

Untitled

a guest
Aug 15th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <errno.h>
  4. #include <postgresql/libpq-fe.h>
  5. #include <postgresql/9.5/server/postgres.h>
  6.  
  7. struct DbConfig {
  8. char host[30];
  9. char dbName[30];
  10. char userName[30];
  11. char password[30];
  12. }
  13.  
  14. int main(int argc, char *argv[]) {
  15. struct DbConfig dbConfig;
  16. dbConfig.host = "host";
  17. dbConfig.dbName = "db_name";
  18. dbConfig.userName = "user_name";
  19. dbConfig.password = "password";
  20.  
  21. PGconn *con;
  22. PGresult *res;
  23.  
  24. con = PQsetdb(
  25. dbConfig.host,
  26. "",
  27. NULL,
  28. NULL,
  29. dbConfig.userName,
  30. dbConfig.password);
  31. if (PQstatus(con) == CONNECTION_BAD) exit(1);
  32. res = PQexec(con, "select 1");
  33.  
  34. PQclear(res);
  35. return 0;
  36. }
Add Comment
Please, Sign In to add comment