C + + operation MySQL Method summary (3)

Source: Internet
Author: User

C + + by mysql++ how MySQL is manipulated

Operation with vs2013 and 64-bit mSQL 5.6.16

The database name and table data used in the project are described in the summary of the C + + operation MySQL Method (1)

Mysql++ is an officially published API for the C + + language designed for MySQL. Mysql++ is a re-encapsulation of MySQL's C-api, which is developed and written with STL (Standard Template Language) and provides a set of mechanisms for C + + developers to manipulate databases as easily as they do with STL containers.

http://tangentsoft.net/mysql++/

First, the compilation of mysql++ (VS2013)

1, open mysql-3.2.1 under the vc2008 in Mysql++.sln, will be prompted to upgrade, click OK

2, in many open projects, most of them are examples, we just need to compile MYSQLPP, get the Mysqlpp_d.dll and mysqlpp_d.lib required to generate (debug)

or Mysqlpp.dll and Mysqlpp.lib (under release)

3. Add D:\Program files\mysql\mysql Server 5.6\include to the included directory of the MYSQLPP project (depending on the path)

4. Add D:\Program files\mysql\mysql Server 5.6\lib to the Library directory of the MYSQLPP project (depending on the path)

5. Ensure that Libmysql.lib has been added to the additional dependencies of the MYSQLPP project

6, if the use of MySQL is 64-bit, you also need to change the project's solution platform from Win32 to x64

7. Copy the Libmysql.dll from the D:\Program files\mysql\mysql Server 5.6\lib (depending on the path) to the project, and the. cpp,.h file is located under the same path

8. compile MYSQLPP, generate required Mysqlpp_d.dll and Mysqlpp_d.lib (debug) or Mysqlpp.dll and Mysqlpp.lib (under release)

9, the use of mysql++-3.2.1 in the Install.hta will all include files a place, easy to manage

Here for the D:\mysqllib\mysqlplus\include.

At the same time , Mysqlpp_d.dll and Mysqlpp_d.lib,Mysqlpp.dll and Mysqlpp.lib were placed under the D:\mysqllib.

Second, the operation of MySQL through the mysql++

1. Create a new empty project

2. Add D:\mysqllib\mysqlplus\include and D:\Program files\mysql\mysql Server 5.6\include to the project's include directory (depending on the path)

(Mysql++.h in #mysql + + include mysql_version.h in MySQL Server 5.6)

3. Add D:\mysqllib to the project's library directory (depending on the path)

4. Add Mysqlpp.lib to Additional dependencies

(*3.4 step can also add #pragma comment (lib, "D:\\mysqllib\\mysqlpp.lib") at the beginning of the program code to import Mysqlpp.lib)

5, if the use of MySQL is 64-bit, you also need to change the project's solution platform from Win32 to x64

6, the D:\mysqllib (according to the specific path) under the Mysqlpp.dll and D:\Program files\mysql\mysql Server 5.6\lib (depending on path)

Libmysql.dll copied to the project, and the. cpp,.h file is located under the same path

At this point, all the relevant configurations are complete

Program code

Main.cpp

#include <mysql++.h>#include<iostream>#include<iomanip>using namespacestd;intMainintargcChar*argv[]) {Mysqlpp::connection Conn (false); Mysqlpp::setcharsetnameoption*opt =NewMysqlpp::setcharsetnameoption ("GBK");    Conn.set_option (opt); if(Conn.connect ("Booktik",                    "localhost",                    "Root",                    "123456") {conn.query ("set names ' GBK '"); Mysqlpp::query Query= Conn.query ("SELECT * from book"); Mysqlpp::usequeryresult Res=Query.use (); if(res) { while(Mysqlpp::row Row =Res.fetch_row ()) {cout&LT;&LT;SETW (9) <<"BookName:"<< row["BookName"] <<Endl; cout<< SETW (9) <<"Size:"<< row["size"] <<Endl; }        }        Else{Cerr<<"Failed to get item list:"<< Query.error () <<Endl; return 1; }    }    Else{Cerr<<"DB Connection failed:"<< Conn.error () <<Endl; return 1; } System ("Pause");}

Run results

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.