Access MySQL database under Windows in C + +

Source: Internet
Author: User

After the MySQL installation is successful, we can access it in a high-level language. Win7 Access method:

This test uses eclipse, compiled with MINGW64

First, include the path, then include the library, and also note that the Libmysql is listed separately.

The C + + test code is:

#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include "mysql.h"
int main (int argc, char* argv[])
{
int res,j;
MySQL MySQL;
Mysql_res *resultset;
Mysql_row ROW;
Mysql_init (&mysql);//Initialize MySQL
Password change to your own password, test for the database name, your own any one, root for the user name, other basic fixed
if (!mysql_real_connect (&mysql, "localhost", "root", "password", "Test", 3306, NULL, 0))
{
printf ("\ nthe database connection error");//Print success Information
}
Else
{
printf ("\ n database connection succeeded \ n"); //
}
Mysql_close (&mysql); Turn off MySQL
return 0;
}

Access MySQL database under Windows in C + +

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.