#include <mysql/mysql.h>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
using namespace std;
int main(){
MYSQL _sql;
mysql_init(&_sql);
if(!mysql_real_connect(&_sql, "localhost", "root", "123", "shiyao", 0, NULL, 0)){
cout<<"not connected!!"<<endl;
cout<<mysql_error(&_sql)<<endl;
}
else{
cout<<"connected!!"<<endl;
}
//get the result from the executing select query
char *query = "SELECT * FROM test1";
int t = mysql_real_query(&_sql, query, (unsigned int)strlen(query));
if(t){
cout<<"Error making query:"<<mysql_error(&_sql);
}
MYSQL_RES* res = mysql_store_result(&_sql);
if(!res){
cout<<"res failed!"<<endl;
}
MYSQL_ROW row;
while (row = mysq
C++调用MySQL实例
最新推荐文章于 2023-11-12 22:58:27 发布