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