Summary of C ++ methods for operating mysql (3)

Source: Internet
Author: User
Summary of C ++ methods for operating mysql (3) C ++ methods for operating mysql through mysql ++

Use vs2013 and 64-bit msql 5.6.16 for operations

For the database names and table data used in the project, refer to the introduction in C ++ mysql operation method summary (1 ).

Mysql ++ is an officially released C ++ language API designed for MySQL. Mysql ++ is the re-encapsulation of Mysql's C-Api. it is developed and written using STL (Standard Template Language, it also provides a mechanism for C ++ developers to operate databases as conveniently as operating STL containers.

Http://tangentsoft.net/mysql++/

1. Mysql ++ compilation (VS2013)

1. open mysql ++. sln in vc2008 under mysql-3.2.1, and you will be prompted to upgrade it. click OK.

2. most of the projects opened are examples. we only need to compile mysqlpp to obtain the mysqlpp_d.dll and mysqlpp_d.lib needed for generation (under debug)

Or mysqlpp. dll and mysqlpp. lib (under release)

3. add D:/Program Files/MySQL Server 5.6/include to the inclusion Directory of the mysqlpp project (depending on the specific path)

4. add D:/Program Files/MySQL Server 5.6/lib to the Library Directory of the mysqlpp project (depending on the specific path)

5. make sure that libmysql. lib has been added to the additional dependencies of the mysqlpp project.

6. if mysql is 64-bit, you must change the project solution platform from win32 to x64.

7. set "D:/Program Files/MySQL Server 5.6/lib" (depending on the specific path) to libmysql. copy dll to the project, and. cpp ,. the H file is located in the same path

8, Compile mysqlpp and generate the required mysqlpp_d.dll and mysqlpp_d.lib (under debug) Or mysqlpp. dll and mysqlpp. lib (under release)

9. use install. hta in mysql ++-3.2.1 to store all the include files in one place for ease of management.

Here, for D:/mysqllib/mysqlplus/include

At the same timeMysqlpp_d.dll and mysqlpp_d.lib, Mysqlpp. dll and mysqlpp. lib are stored in D:/mysqllib.

2. operate Mysql through mysql ++

1. create an empty Project

2. add D:/mysqllib/mysqlplus/include and D:/Program Files/MySQL Server 5.6/include to the project inclusion Directory (depending on the specific path)

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

3. add D:/mysqllib to the Library Directory of the project (depending on the specific path)

4. add mysqlpp. lib to the additional dependency

(* You can add # pragma comment (lib, "D: // mysqllib // mysqlpp. lib") at the beginning of the program code to import mysqlpp. lib)

5. if mysql is 64-bit, you must change the project solution platform from win32 to x64.

6. set mysqlpp. dll and D:/Program Files/MySQL Server 5.6/lib (depending on the specific path)

Copy libmysql. dll to the project, and the. cpp and. h files are located in the same path.

Now, all the configurations are complete.

Program code

Main. cpp

# Include
 
  
# Include
  
   
# Include
   
    
Using namespace std; int main (int argc, char * 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 <
    
     

Running result

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.