Refer to this blog: http://www.tuicool.com/articles/mUZNne
Configuration: The VS2010 project property contains a directory and a library directory.
Include directory: C:\Program files\mysql\mysql Server 5.6\include
Library directory: C:\Program files\mysql\mysql Server 5.6\lib
Linker-Input-Additional dependencies join: Libmysql.lib
Copy libmysql.lib under C:\Program files\mysql\mysql Server 5.6\lib to the C:\Windows folder
Example: an EMP table connected to the Test1 database, all the contents of the output table
#include <iostream>#include"winsock.h"#include"mysql.h"using namespacestd;intMain () {MYSQL*MySQL; MySQL=Mysql_init (NULL); Char* sql ="SELECT * from emp"; Mysql_res*result; Mysql_row ROW; intR, Num; if(Mysql_real_connect (MySQL,"localhost","Root"Null"test1",3306Null0) {mysql_set_character_set (MySQL,"GBK"); if(!mysql_query (MySQL, SQL)) {Result=mysql_store_result (MySQL); if(Result = =NULL)return 0; Num=mysql_num_fields (Result); unsignedLong* lengths =mysql_fetch_lengths (Result); while(row =mysql_fetch_row (Result)) { for(R =0; R < Num; ++r) {cout<<row[r]<<' '; } cout<<Endl; } mysql_free_result (Result); } mysql_close (MySQL); } return 0;}
The functions in the API section of the MySQL Chinese reference manual are: Http://www.cbi.pku.edu.cn/chinese/documents/csdoc/mysql/manual_Clients.html#C
"mysql5.6" Connection vs2010