如何在c++设计的程序中连接数据库
怎么在c++设计的程序中连接数据库
谢谢大家给我点资料,最好是个课程设计管理系统之类的连接数据库
------解决方案--------------------
谢谢大家给我点资料,最好是个课程设计管理系统之类的连接数据库
------解决方案--------------------
- C/C++ code
http://hi.baidu.com/%B3%CB%B7%E7%CC%A4%C0%CB2008/blog/item/28582bf0aaa689d07931aadf.html
------解决方案--------------------
http://hi.baidu.com/%B3%CB%B7%E7%CC%A4%C0%CB2008/blog/item/28582bf0aaa689d07931aadf.html
http://hi.baidu.com/%B3%CB%B7%E7%CC%A4%C0%CB2008/blog/item/28582bf034386fcf7931aa57.html
------解决方案--------------------
MYSQL *mysqlcon;//数据库连接
/****************************************************
** 功能: 初始化数据库连接
入参:
HostName - 主机名或IP地址
UserName - 数据库用户名
PassWord - 数据库口令
DbName - 数据库名
char_set - 字符集名称
Port - 数据库的连接端口
U_Sock - 数据库的连接套接字
Flag - 标志
** 返回值:int
** 1 成功;
** 0 失败;
****************************************************/
int Login( const char *HostName,const char *UserName,
const char *PassWord, const char *DbName,
const char *char_set = "",unsigned int Port=0,const char *U_Sock="",unsigned int Flag=0)
{
if(!mydata)
{
mysqlcon = mysql_init((MYSQL *)NULL);
if(strlen(char_set) > 0)
{
mysql_options (mysqlcon , MYSQL_SET_CHARSET_NAME , char_set);
}
}
if(mysqlcon)
{
if(mysql_real_connect(mysqlcon, HostName, UserName, PassWord, DbName,
Port, U_Sock, Flag))
{
return 1;
}
else
{
sprintf(m_szErrorStr, "real_connect fail:\t%s\n", mysql_error(mysqlcon));
mysql_close( mysqlcon );
mysqlcon = NULL;
return 0;
}
}
return 0;
}
mysql数据库