MySQL connection problem with devc++

Source: Internet
Author: User

0. Introduction

  MySQL as a current mainstream open source relational database, has been widely concerned by everyone. Devc++ is also an open source, simple C + + editor that has a simpler and faster compilation than vs. But there are few links to MySQL connection devc++ on the Internet, most of which are MySQL link vs, or connection tutorials for Java,python. This article, which will compensate for this shortcoming, I spend a lot of time querying similar information from multiple websites and will be integrated. If there are some inappropriate places, please forgive the reader.

1. Preparatory work

  When devc++ link data, we first need some preparation to ensure the subsequent operation.

1.devc++ Installation Mysql.devpak

Below provides my Baidu network disk share address, can download directly:

Links: Https://pan.baidu.com/s/1Y6q0emGEsaMU5GQZNLf3YQ

Password: 4lti

MySQL connecter/c++ website Address: https://dev.mysql.com/downloads/connector/cpp/1.1.html

After the installation is complete, the package Manager can be found in the Devc++ toolbar, i.e. the installation is complete.

    

2.MySQL of installation Preparation

Installation version varies from person to person, one of the following is available on the official website: https://dev.mysql.com/downloads/installer/

When the installation is complete, locate the following path

    

(I'm using MySQL5.7 here.)

2. Start operation1. associating Files  

Project---project Properties--parameters, open the following

    

    Enter-wall in the C compiler

Enter-W in the C + + compiler

Link, add a library or object, (Find devc++ installation directory/LIB/LIBMYSQL.A), add libmysql.a the library; Fill in such as-lmysql

As follows:

    

    Project---project Properties--File/directory

    

    Add separately: Library directory: (just MySQL directory)/lib

Include file directory: (just MySQL directory)/include

2. Here, the link is done almost, and then the C + + header file is introduced
#include <mysql.h>

You can do it.

MySQL connection database operation in 3.c++
1     #defineHOST "localhost"2     #defineUSER "Root"//(write your own user name here)3     #definePASSWORD "***************"//(Write your own database password here)4     #defineTABLE "Stock"//(write your own library name here, my library is the stock)5     #definePORT 33066 7Mysql_init (&mycont);//Initialize handle8Mysql_real_connect (&mycont,host,user,password,table,port,null,0);//Open Database9Mysql_set_character_set (&mycont,"GBK");//Set character formattingTenMysql_close (&mycont);//Close the database

4. End

  Here, the chapter is over, if there is no place, you can contact the author Oh.

MySQL connection problem with devc++

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.