2)codeblock安装
2-1)官网 https://www.codeblocks.org/
2-2)点击下载
2-3)选择对应平台
2-4)安装即可
2-5)配置依赖库和include库
Setting中第三个Compiler
2-6)创建工程
2-7)将libmysql.dll复制到工程中
2-8)运行结果
文件:main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| \#include <iostream>
\#include "mysql.h"
using namespace std;
int main()
{
cout << "Hello, world!" << endl;
MYSQL conn;
int res;
mysql_init(&conn);
if (mysql_real_connect(&conn, "127.0.0.1", "root", "root", "test", 3306, NULL, CLIENT_FOUND_ROWS))
{
printf("connect success!\n");
res = mysql_query(&conn, "insert into account values('lisi','9999')");
if (res)
{
printf("error\n");
}
else
{
printf("OK\n");
}
mysql_close(&conn);
}
else
{
printf("connect errot!\n");
}
return 0;
}
|