本文主要是介绍C++ 访问mysql,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
// x.cpp :
UINT thread_check_msg(LPVOID lpParam)
{
AfxSocketInit();
CDlgName* dlg = (CDlgName*)lpParam;
HWND hwnd;
hwnd = ::FindWindow(NULL, "windowname");
dlg->OtherCheckInfo = false;
try {
if (chekcinfo)
{
//set ui info
mysql_init(&dlg->mysqlC3);
if (!mysql_real_connect(&dlg->mysqlC3, "x7.xx5.xx6.xx9", "?name", "pwd", "?name", 3306, NULL, 0))
{
AfxMessageBox(_T("access db error !"));
}
mysql_query(&dlg->mysqlC3, "SET NAMES 'GB2312'");
if (mysql_real_query(&dlg->mysqlC3, "select from ...",
(unsigned long)strlen("select from ...")))
{
return 0;
}
MYSQL_RES* res;
MYSQL_ROW row;
res = mysql_store_result(&dlg->mysqlC3);
if (NULL == res) { return 0; }
while (row = mysql_fetch_row(res))
{
CString myreaddata2(row[1]);
CString myreaddata1(row[0]);
//other info
}
}
}
catch (CException* e)
{
CString strError;
strError.Format("%s", e);
mysql_close(&dlg->mysqlC3);
MessageBox(NULL, strError, "提示", MB_OK);
return 0;
}
mysql_close(&dlg->mysqlC3);
dlg->OtherCheckInfo = true;
return 0;
}
这篇关于C++ 访问mysql的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!