vc 连接mysql数据库_vc怎样连接mysql数据库

vc连接mysql数据库的方法:首先打开VC6;然后在中间列表框中添加本地安装MySQL的include目录路径;接着选中“Library files”并添加MySQL的Lib目录路径;最后进行编程测试即可。

(5)建议将“libmySQL.lib、libmySQL.dll”拷到你所建的工程的目录下。

这两个文件在D:\Mysql\lib目录下。

三、编程实现

1. 一个简单的小程序,看看是否能连接成功。。。#include #include #include int main()

{

MYSQL mysql;

mysql_init(&mysql); //初始化mysql结构

if(!mysql_real_connect(&mysql,"localhost","myuser","123456","student_db",3306,NULL,0))

printf("\n连接数据库时发生错误!\n");

else

printf("\n连接数据库成功!\n");

mysql_close(&mysql); //释放数据库

return 0;

}

mysql_real_connect(&mysql,"localhost","myuser","123456","student_db",3306,NULL,0)//myuser是我的用户名,“123456”是密码,“student_db”是数据库,3306是端口号

2.实现查询小程序// test.cpp : Defines the entry point for the console application.

//

#include #include #include "StdAfx.h"

#include #include #include #include using namespace std;

//不需要单步调试的就注释掉

//#define STEPBYSTEP

void pause(){

#ifdef STEPBYSTEP

system("pause");

#endif

}

void writeToFile(const char *s)

{

FILE *fp=fopen("info.txt","rw");

fprintf(fp,s);

fclose(fp);

}

/* int main()

{

MYSQL mysql;

mysql_init(&mysql); //初始化mysql结构

if(!mysql_real_connect(&mysql,"localhost","myuser","123456","student_db",3306,NULL,0))

printf("\n连接数据库时发生错误!\n");

else

printf("\n连接数据库成功!\n");

mysql_close(&mysql); //释放数据库

return 0;

}*/

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

cout

运行结果:

至此连接成功。。哈哈。。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值