How Do You Use C++ to Retrieve Data from a PostgreSQL Database on Linux CentOS?

Problem scenario
You have C++ and Postgres installed on a Linux CentOS server.  How do you write C++ programs to retrieve data from Posgres databases?

Solution
Install the official C++ API for Postgresql.  These directions should work on any RedHat distribution of Linux (e.g., CentOS or Fedora).

Run the following from the Linux command prompt:

sudo yum -y install postgresql-devel gcc-c++
sudo cd /usr/bin/
sudo curl http://pqxx.org/download/software/libpqxx/libpqxx-4.0.tar.gz > libpqxx-4.0.tar.gz
sudo tar xvfz libpqxx-4.0.tar.gz
sudo cd libpqxx-4.0
sudo ./configure
sudo make
sudo make install

To read more about the official API for C++ and PostgreSQL, see this GitHub link or the official pdxx.org site (http://pqxx.org/development/libpqxx/).

Leave a comment

Your email address will not be published. Required fields are marked *