Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. //To make use in C/C++, you include these header files
  2. #include "libpq/libpq-fs.h"
  3. #include "libpq-fe.h"
  4. #include <stdlib.h>
  5.  
  6. #include <string.h>
  7. #include <conio.h>
  8.  
  9. //Declare some variables
  10.  
  11. const char *conninfo;
  12. PGconn *conn;
  13. PGresult *preslt;
  14. //Connect to DB
  15.  
  16. conninfo = "dbname = lebl user=postgres password=abcd1234@";
  17.  
  18. /* Make a connection to the database */
  19. conn = PQconnectdb(conninfo);
  20.  
  21. /* Check to see that the backend cfonnection was successfully made */
  22. if (PQstatus(conn) != CONNECTION_OK)
  23. {
  24. fprintf(stderr, "Connection to database failed: %s",
  25. PQerrorMessage(conn));
  26. PQfinish(conn);
  27. }
  28. else
  29. {
  30. printf("Connection Ok");
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement