Chinaunix首页 | 论坛 | 博客
  • 博客访问: 124947
  • 博文数量: 44
  • 博客积分: 2115
  • 博客等级: 大尉
  • 技术积分: 390
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-05 19:58
文章分类

全部博文(44)

文章存档

2012年(4)

2011年(1)

2009年(39)

我的朋友

分类: Mysql/postgreSQL

2009-05-06 19:37:07

今天要做个模拟实验要用到数据库,经同事介绍mysql很强大而且开源所以就试试怎么样,首先用c++连接mysql,具体程序如下,供以后参考!
 注:你必须先保证你安装了mysql数据库,并把安装目录下的lib目录中的libmysql.dll和libmysql.lib复制到你新建的vs2005或者vc++ 6.0项目目录下,并把libmysql.lib引到项目中。

#include "stdafx.h"

#include
//定义socket

#include
#include "mysql.h"

using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    MYSQL mysql;
    mysql_init(&mysql);
    if (mysql_real_connect(&mysql,"localhost","root","密码","数据库名",3306,0,0))
    {
        cout << "The connection is OK!" <         return 0;
    }
    else
    {
        int i = mysql_errno(&mysql);
        const char * s = mysql_error(&mysql);
        cout << s << endl;
    }
}
阅读(694) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~