Database package: Difference between revisions

Line 39: Line 39:
  conn = pq_connect (setdbopts ("dbname", "mydatabase"));
  conn = pq_connect (setdbopts ("dbname", "mydatabase"));
Here, you are specifying a key-value pair. So you want to fill in a key (dbname), and that dbname is mydatabase.  
Here, you are specifying a key-value pair. So you want to fill in a key (dbname), and that dbname is mydatabase.  
Note: If you get an error similar to:
<pre>could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
</pre>
Try connecting via the IP/port instead of the unix socket. e.g.
conn = pq_connect (setdbopts ("dbname", "testdatabase", "host", "localhost", "port", "5433", "user", "pguser", "password", "pguserpassword"))
Now, you are ready to read the db:
Now, you are ready to read the db:
  N = pq_exec_params (conn, "select * from Table1;")
  N = pq_exec_params (conn, "select * from Table1;")
14

edits