Professional Documents
Culture Documents
codeBlocks-16.01-setup
devcpp_v4_9_9_2_setup
xampp-win32-7.0.3-0-VC14-installer
1. my_alloc.h :
2. my_list.h :
3. mysql.h
4. mysql_com.h
5. mysql_time.h
6. mysql_version.h
7. typelib.h
int main()
{
MYSQL* conn;
conn = mysql_init(0);
conn = mysql_real_connect(conn,"localhost","root","root","mca",0,NULL,0);
if(conn)
cout<<"connection to mca databse successful "<<endl;
else
cout<<"connection problem: "<<mysql_error(conn)<<endl;
int main()
{
MYSQL* conn;
MYSQL_ROW row;
MYSQL_RES *res;
int qstate;
conn = mysql_init(0);
if(conn)
cout<<"connection object ok, conn="<<conn<<endl;
else
cout<<"conn object problem: "<<mysql_error(conn);
conn = mysql_real_connect(conn,"localhost","root","","mca",0,NULL,0);
if(conn)
{
cout<<"connected to database mca"<<endl;
string id,name,phone;
cout<<"enter id: "<<endl; cin>>id;
cout<<"enter name: "<<endl; cin>>name;
cout<<"enter phone: "<<endl; cin>>phone;
if(!qstate)
cout<<"record inserted successfully..."<<endl;
else
cout<<"query problem: "<<mysql_error(conn)<<endl;
if(!qstate)
{
res = mysql_store_result(conn);
while(row=mysql_fetch_row(res))
{
cout<<"id: "<<row[0]<< " "
<<"name: "<<row[1]<< " "
<<"phone: "<<row[2]<<endl;
}
}
else
{
cout<<"query error: "<<mysql_error(conn)<<endl;
}
}
else
{
cout<<"connection problem: "<<mysql_error(conn)<<endl;
}
mysql_close(conn);
return 0;
}
output: