vs2012 使用mysql_vs2012连接mysql

1. 下载mysql安装包,记住安装的时候选择完全安装,不然是找不到mysql.h的

2. vs2012中新建一个win32 console项目,右击项目,选择属性。 找到 配置属性--->VC++目录----->包含目录添加要包含的目录,这里选择上面安装后的include. 找到 配置属性--->VC++目录----->库目录添加要包含的目录,这里选择上面安装后的lib/opt文件夹. 找到 配置属性--->链接器----->输入----->附加依赖项添加依赖项:libmySQL.lib

3. 将libmySQL.dll拷贝到生成的exe文件的目录中。

测试代码:

#include

#include

#include "my_global.h"

#include "mysql.h"

int main(int argc, char *argv[])

{

MYSQL my_connection;

mysql_init(&my_connection);

//填写用户和密码

if (mysql_real_connect(&my_connection, "localhost", "****", "****","test",0,NULL,CLIENT_FOUND_ROWS))

{

printf("Connection success\n");

int res = mysql_query(&my_connection, "INSERT INTO Orders(order_num, order_date, cust_id)VALUES(20011, '2004-02-08', '1000000001');");

if (!res) {

printf("Inserted %lu rows\n",(unsigned long)mysql_affected_rows(&my_connection));

}

else {

fprintf(stderr, "Insert error %d: %s\n",mysql_errno(&my_connection),mysql_error(&my_connection));

}

mysql_close(&my_connection);

}

else {

fprintf(stderr, "Connection failed\n");

if (mysql_errno(&my_connection)) {

fprintf(stderr, "Connection error %d: %s\n", mysql_errno(&my_connection), mysql_error(&my_connection));

}

}

system("pause");

return EXIT_SUCCESS;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值