The libpq library is a C language API that provides access to the PostgreSQL back end. In fact, most of the provided client tools (like psql) use this library as their connection route to the back end.
The libpq provides many functions that can control nearly every aspect of the client/server. Although an in-depth discussion of every function is outside the scope of this chapter, the two most popular functions it provides are as follows:
PQconnectdb. Connects to a database.
PQexec. Sends and executes a query to the back end.
PQconnectdb also provides the following functions:
PQreset. Resets client/server communication.
PQfinish. Closes the database connection.