日期:2014-05-16  浏览次数:21075 次

Run-Time Check Failure #2 - Stack around the variable 'mysql' was corrupted.
BOOL CMySQLData::connectmysql(){
MYSQL mysql; //数据库连接句柄
//MYSQL *mysql = (MYSQL *)malloc(sizeof(MYSQL));
mysql_init (&mysql);
if(!mysql_real_connect(&mysql,"localhost","root","root","tennis",3306,NULL,0))
{//mydb为你所创建的数据库,3306为端口号,可自行设定
  AfxMessageBox(L"数据库连接失败");  
  return FALSE;
 
}
else{
AfxMessageBox(L"连接成功");
//mysql_close(&mysql);
return TRUE;
}

连接成功了的,messagebox 连接成功出现了的,可是出现一个越界的对话框,提示是
Run-Time Check Failure #2 - Stack around the variable 'mysql' was corrupted.
请问这是哪里出错了?

如果还要代码请说下,菜鸟真心求教 - -

------解决方案--------------------
MYSQL句柄不是这么用的。
这样用下去:
MYSQL *mysql = NULL;
mysql = mysql_init(NULL);

if(!mysql_real_connect(mysql,"localhost","root","root","tennis",3306,NULL,0))
{
}

找一个例子试试,前边有的。
------解决方案--------------------
帮顶!