Database Reference
In-Depth Information
Using PQpingParams
The
PQpingParams
function returns the server status. The syntax for
PQpingParams
is as follows:
PGPing PQpingParams(const char **keywords,
const char **values,
int expand_dbname);
The
PQpingParams
function can return the following values:
•
PQPING_OK
: This means that the server is available, that is, the server is
accepting connections
•
PQPING_REJECT
: This means that the server is rejecting the connections
•
PQPING_NO_RESPONSE
: This means that there is no response from the server
•
PQPING_NO_ATTEMPT
: This means that there is a bad parameter and no
connection attempt was made
Executing a query
We have discussed how to connect to the PostgreSQL server; the second step is
executing the query. The
libpq
library also provides multiple functions to execute
the query in a similar way to how it provides multiple functions to connect to the
PostgreSQL server.
Using PQexec
The
PQexec
function sends the command (query) to the connected PostgreSQL
server. The irst parameter is the same connection object returned by the connection
functions discussed previously. The syntax for
PQexec
is as follows:
PGresult *PQexec(PGconn *conn, const char *command);