Download the mysql00000000-3.1.0.tar.gz source code package from the official website. decompress the package and find three folders, including "vc2003", "vc2005", and "vc2008, open the project in your vs version to compile MySQL ++. Check the engineering properties before compilation. (There are many projects in the solution. Compile "mysqlpp" only, the header file and the path to the link library are mysql5.1 by default. If you install another version, you must change it. After compilation, a dynamic library and a static library are generated in the debug or release folder. You can create a new path to store these library files and add them to the PATH variable. By now, 99% is successful, double-click "install. "HTA" to install. After installation, it is found that there is an include folder under the installation path, which contains the header file of MySQL ++. With include and Lib, you can write a test code:
Mysqlpp: Connection _ conn; _ Conn. set_option (New mysqlpp: setcharsetnameoption ("GBK"); // set the Chinese Character Set _ Conn. set_option (New mysqlpp: multistatementsoption (true); If (_ Conn. connect ("test", "localhost", "root", "sa", 3306) {int _ id; STD: String _ name; mysqlpp :: query _ query = _ Conn. query ("select * From mytable"); mysqlpp: storequeryresult _ rs = _ query. store (); For (uint I = 0; I <_ rs. num_rows (); I ++) {_ id = atoi (_ rs [I] [0]. c_str (); If (_ rs [I] [1] = mysqlpp: NULL) _ name = "null "; else _ name = _ rs [I] [1]. c_str (); printf ("% d % s \ n", _ id, _ name. c_str ();} _ Conn. disconnect ();}
Running result:
1 Tom
2 null
3 Zhang San
If the link fails or the DLL cannot be found, check whether the generated library file is correctly referenced.