Use MySQL_MySQL in C ++

Source: Internet
Author: User
The software on my computer is as follows: VS2012MySQL56 is a 64-bit win811 operating system. download and install MySQL2 configuration (1) properties in the project "C43; 43; general add the include Directory: MY_ SQL directory include (2) properties in the project. the software on my computer is as follows:

VS2012

For MySQL 5.6

The operating system is 64-bit win8.1

1. prerequisites

Download and install MySQL

2. configuration

(1) add the include Directory: MY_ SQL directory/include to project properties C ++ general.

(2) add an additional Library Directory: MY_ SQL directory/lib

(3) add an additional dependency in "properties" connector "input": libmysql. lib

3. Notes

If the above configuration is followed but the compilation fails, the following message is displayed:

1> generating code...

1> BaseDB. obj: error LNK2019: external symbol that cannot be parsed _ mysql_init @ 4, which is in the function "public: bool _ thiscall BaseDB: openConnect (void )"(? In openConnect @ BaseDB @ QAE_NXZ), BaseDB is referenced. obj: error LNK2019: external symbol that cannot be parsed _ mysql_real_connect @ 32, which is in the function "public: bool _ thiscall BaseDB: openConnect (void )"(? In openConnect @ BaseDB @ QAE_NXZ), BaseDB is referenced. obj: error LNK2019: external symbol that cannot be parsed _ mysql_query @ 8, which is in the function "public: struct st_mysql_res * _ thiscall BaseDB: doQuery (class std: basic_string , Class std: allocator > Const &)"(? DoQuery @ BaseDB @ QAEPAUst_mysql_res @ ABV? $ Basic_string @ DU? $ Char_traits @ D @ V? $ Allocator @ D @ Z) is referenced in 1> BaseDB. obj: error LNK2019: external symbol that cannot be parsed _ mysql_store_result @ 4, which is in the function "public: struct st_mysql_res * _ thiscall BaseDB: doQuery (class std: basic_string , Class std: allocator > Const &)"(? DoQuery @ BaseDB @ QAEPAUst_mysql_res @ ABV? $ Basic_string @ DU? $ Char_traits @ D @ V? $ Allocator @ D @ Z) is referenced in 1> BaseDB. obj: error LNK2019: external symbol that cannot be parsed _ mysql_close @ 4, which is in the function "public: void _ thiscall BaseDB: closeConnect (void )"(? CloseConnect @ BaseDB @ QAEXXZ) is referenced in 1> DBUtil. obj: error LNK2019: external symbol that cannot be parsed _ mysql_free_result @ 4, which is in the function "public: static bool _ cdecl DBUtil: checkUserLogin (class std: basic_string , Class std: allocator > Const &, class std: basic_string , Class std: allocator > Const &)"(? CheckUserLogin @ DBUtil @ SA_NABV? $ Basic_string @ DU? $ Char_traits @ D @ V? $ Allocator @ DZ) referenced 1> E:/Flighting/MySQLtest/ConsoleApplication1/Debug/ConsoleApplication1.exe: fatal error LNK1120: 6 external commands that cannot be parsed 1>

1> generation failed.

The cause of this problem is: MySQL64-bit is installed, while VS2012's default running platform is 32-bit, so it is not supported.

There are two solutions: (1) there is a configuration manager in the upper-right corner of project properties. change the running platform of your project to X64 (if not, create a new one)

(2) if other 32-bit additional libraries have been introduced in the project, rashly changing to 64-bit causes the original library compilation to fail, in this way, you cannot search for a lib and dll named mysql32 on the Internet.

Finally, copy libmysql and dll to System32/SysWow64 if you cannot find libmysql. dll.

Code example:

# Include
         
          
# Include
          
           
# Include
           
            
# Include
            
             
# Include
             
              
# Include
              
                Using namespace std; int main () {const char user [] = "root"; // username const char pswd [] = "root "; // password const char host [] = "localhost"; // or "127.0.0.1" const char table [] = "test"; // database unsigned int port = 3306; // server port MYSQL myCont; MYSQL_RES * result; MYSQL_ROW SQL _row; MYSQL_FIELD * fd; char column [32] [32]; int res; mysql_init (& myCont ); if (mysql_real_connect (& myCont, host, user, ps Wd, table, port, NULL, 0) {cout <"connect succeed! "<
               
                 Name);} j = mysql_num_fields (result); for (I = 0; I
                
               
              
             
            
           
          
         

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.