#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实例
最新推荐文章于 2024-08-15 23:37:12 发布
本文详细介绍了如何在C++应用程序中使用MySQL Connector/C++库来连接和操作MySQL数据库,包括建立连接、执行SQL查询、处理结果集等关键步骤,适合C++开发者参考学习。
摘要由CSDN通过智能技术生成