C ++ uses mysql APIs for connection issues.

Source: Internet
Author: User

C ++ uses mysql APIs for connection issues.

Record related problems in your use to help you solve the same problems.

  • For more information about the various configurations in VS, please note that the mysql version I am using is 5.6 and there is no [MySQL Server \ lib \ opt] path, set this item to MySQL Server \ lib.

  • If the following error occurs:
    1> main. obj: error LNK2019: external symbol that cannot be parsed _ mysql_server_init @ 12, which is referenced in function _ main 1> main. obj: error LNK2019: external symbol that cannot be parsed _ mysql_init @ 4, which is referenced in function _ main 1> main. obj: error LNK2019: external symbol that cannot be parsed _ mysql_real_connect @ 32, which is referenced in function _ main 1> main. obj: error LNK2019: external symbol that cannot be parsed _ mysql_options @ 12, which is referenced in function _ main

    Because the first step was followed, the win32 project was created, and now the system and mysql use x64, which can be changed to x64. The procedure is as follows:
    . Project-> properties-> Configuration Manager
    Active solution platform. select new from the drop-down list. A new check box is displayed. Select X64 from the shortcut menu.
    Learn from here

  • Then you can write a simple c program to test whether the program is successful.
    # Include "winsock. h "# include" iostream "# include" mysql. h "# pragma comment (lib," ws2_32.lib ") # pragma comment (lib," libmysql. lib ") using namespace std; void main () {MYSQL mydata; mysql_library_init (0, NULL, NULL); // initialize MySQL c api library mysql_init (& mydata ); // initialize the data structure of mydata. mydata is the MYSQL object mysql_options (& mydata, MYSQL_SET_CHARSET_NAME, "gbk"); // connection options: add GBK character set support // connection function if (mysql_real_connect (& mydata, "localhost" , "Root", "1234", "demo", 3306, 0, 0 )! = NULL) cout <"database connection OK! "<Endl ;}

    Note the following parameters in the mysql_real_connect function (& mydata, "localhost", "root", "1234", "demo", 3306, 0, 0 ), generally, you need to change the 2, 3, 4, and 5 parameters to the database location, user name, password, and name of the database to be connected.

  • If the # include "stdafx. h" ERROR occurs in the Code, the source file cannot be opened. For more information, see here.
    This header file is a pre-compiled header file. If you do not tell VS information when creating a project, you certainly do not know what this is.

  • # Error: Building MFC application with/MD [d] (CRT dll version) requires MFC shared dll version. Please # define _ AFXDLL
    See here

  • C ++ fatal error C1083: the pre-compiled header file cannot be opened: ". \ Debug \ router. pch"
    See here. This problem is also a problem of pre-compiled header files.


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.