Creating a MySQL database connection using C++ is really easy. But for a beginner it can be really hard to find the correct procedure cause it will gave really troubles. At the first time when I'm doing it it took me quite some time to make it work. So I'm going to explain how to make a connection to the MySQL database using C++ code. We use the library called boost to make the connection.
Step 1 (Download the boost library)
First step is to download the boost library. You can download it from here from the official download page Or you can download the one I've compressed and uploaded which is smaller in size from here.
Step 2 (Create the project using Visual Studio 2008)
First go to File --> New --> Project and you'll get a screen like this.
|mysql c++ connection example|
Select Visual C++ --> Win 32 --> Win 32 Console Application and give a name to the project and press OK.
Then set Application Type to Console Application and remember to tick the empty project. and click finish.
Then Right Click the project and add new Item a cpp source file called Connect.cpp.
Copy the boost folder into the project folder. In this example the folder is Visual Studio 2008\Projects\MySQLConnection\MySQLConnection folder.
Then download this header and dll files and extract them into the same folder Visual Studio 2008\Projects\MySQLConnection\MySQLConnection folder.
Then the final step is right cilck on the Project and go to
Properties --> Configuration Properties --> C/C++ --> General .
On the right hand side set the "Additional Include Directories" value to ".\" value. (with out the quotes)
That's it build your project and run the project. And one more final thing when you run the project set the "Solution Configuration" to Release mode. In the Debug Mode I had some error which I still don't no why.