Home > Articles > Data > MySQL

Accessing a MySQL Database from a C++ CGI Program

  • Print
  • + Share This
If you want to access a MySQL database through CGI, C++ is a great option. Sure, you can use other languages such as PHP or Perl, and they might be easy to use, but C++ has the advantage of being fast, powerful, and fully compiled, thereby hiding your original code. In this article, Jeff Cogswell shows you how you can write CGI programs in C++ to access a MySQL database.
Like this article? We recommend

Like this article? We recommend

If you want to access a MySQL database through CGI, C++ is a great option. Sure, you can use other languages such as PHP or Perl—but although these other languages might be easy to use, C++ has the advantage of being fast, powerful, and fully compiled, thereby hiding your original code. In this article, I show you how you can write CGI programs in C++ that can access a MySQL database.

Tools I Used

To access a MySQL database from C++, I used the MySQL Connector/C++, also known as MySQL++. (There are actually other C++/MySQL libraries available as well, which probably work fine; however, this is the one actually built by the MySQL people.) The MySQL++ library includes a set of classes that allow easy access to MySQL.

TIP

You can find the (free!) MySQL++ library at http://www.mysql.com/products/mysql++/index.html. The online docs are at http://www.mysql.com/documentation/mysql++/index.html.

For the CGI portion of your program, you can do without a CGI library, but using one can make your life a lot easier. I looked on the Web and discovered many CGI libraries for C++. The one I settled on is the official GNU library, called cgicc. You can find it at http://www.cgicc.org.

The Web sites for these libraries include information on downloading, building, and installing the two libraries.

  • + Share This
  • 🔖 Save To Your Account