Environment configuration
1. Project--Properties->vc++ directory,
Add include directory: C:\Program files\mysql\mysql Server 5.7\include
Add Library directory: C:\Program files\mysql\mysql Server 5.7\lib
2. Linker-Input: Add Libmysql.lib
3. Place Libmysql.dll (under the \mysql\mysql Server 5.7\lib directory) in the project catalog debug
4. Create a database class MySQLdb, code:
1 1#include"winsock2.h" //This is mysqlDB.h2 2#include"mysql.h"3 3 classmysqldb{4 4 5 5 Private:6 6 Const Char*host;7 7 Const Char*user;8 8 Const Char*pwd;9 9 Const Char*db;Ten Ten BOOLFlag; One One A A Public: - -MYSQL *con; - -Mysql_res *Res; the theMysql_field *field; - -Mysql_row ROW; - - Public: - - + +MySQLdb (Const Char*host,Const Char*user,Const Char*pwd,Const Char*db): Host, user, - -pwd (PWD), DB (db) {}; + + BOOLConnect (); A A BOOLTb_query (BOOLFlagChar*sqlstr); at at }; - -#include"stdafx.h" -#include"mysqlDB.h" //This is mysqlDB.cpp - - BOOLMysqldb::connect () in { -con = Mysql_init (0); to if(!mysql_real_connect (Con, host, user, PWD, DB,3306Null0))return false; + Else return true; - } the BOOLMysqldb::tb_query (BOOLFlagChar*sqlstr) * { $ Panax Notoginseng if(flag) { - mysql_query (Con, sqlstr); theres =Mysql_store_result (con); + } A Else return false; the return true; + } -
VS2013 using the MySQL API to connect to the database