C + + Connect MySQL database

Source: Internet
Author: User

1. Install MySQL Database

2. Three files required after MySQL installation mysql.h libmysql.lib libmysql.dll.

#include <Windows.h>#include<stdio.h>/*#include <WinSock.h>*/#include<mysql.h>intMain () {MYSQL*con = Mysql_init (MySQL *)0); Mysql_res*Res;    Mysql_row ROW; Chartmp[ -]; //Database Configuartion    Chardbuser[ -] ="Root"; Chardbpasswd[ -] =""; Chardbip[ -] ="127.0.0.1"; Chardbname[ -]="MySQL"; Chartablename[ -]="Test"; Char*query=NULL; intx; inty; intRT; unsignedintT; intCount =0; printf ("input x,y\n"); scanf ("%d,%d", &x,&y);    Fflush (stdin); printf ("input ouver\n"); Con= Mysql_init (0);//The first step of initializing    if(Con!=null&&mysql_real_connect (Con,dbip,dbuser,dbpasswd,dbname,3306Null0))//The second step connects the database    {        if(!mysql_select_db (Con,dbname))//Step three Select the database{con->reconnect =1; Query="SELECT * from user"; if(Rt = Mysql_real_query (Con,query,strlen (query)))//Fourth Step execution command{Query=""; }            Else{res= Mysql_store_result (con);//Fifth Step get return results                 while(row =mysql_fetch_row (RES)) {                     for(t=0; T<mysql_num_fields (res); t++) {printf ("%s", row[t]); }                }            }                }    }}

C + + Connect MySQL database

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.