当前位置:Gxlcms > mysql > c++-vs下链接mysql数据库出错

c++-vs下链接mysql数据库出错

时间:2021-07-01 10:21:17 帮助过:14人阅读

mysqlc++数据库vs2010

数据库初始化没有问题,可以连接
使用mysql_query出现问题,无法查询
代码如下:
MYSQL_RES * result = NULL;
CString temp ( "select username from user_login where username = ");
MYSQL_ROW row;
CString douhao("'");
int res;
CString i_query = temp + douhao + name + douhao ;
if ((res = mysql_query(&mysql, (LPSTR)(LPCTSTR)i_query) )!= 0) //mysql_query函数为0时说明成功,mysql_query函数里面的sql语句不应该包含分号
{
mysql_errno(&mysql);
return -1;
}
else
{
res = mysql_field_count(&mysql);
if ((result = mysql_store_result(&mysql)) == NULL)
{
return -1;
}
else
{
//row = mysql_fetch_row(result);
//if (passwd == row[1])
return 0; //返回值只可能有一个,因为名字是主键
/* else
return -1;*/
}
}
mysql_free_result(result);
result = NULL;

人气教程排行