VS2013 using the MySQL API to connect to the database

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.