数据库
首页 > 数据库> > C++ 访问mysql

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;
}

标签:dlg,res,mysqlC3,C++,访问,mysql,NULL,row
来源: https://blog.csdn.net/weixin_53370274/article/details/117839661