Hi,all my friends!
Recently,I learn mariaDB database.
plz check following codes:
MYSQL g_sqlCon;
mysql_init(&g_sqlCon);
if (!mysql_real_connect(&g_sqlCon, "109.130.15.111","pesystem","tstcpe","repairfunction",1081,NULL,0))
{
AfxMessageBox(_T("connect error!"));
}
else
{
char update_server[200];
memset(update_server, NULL, 200);
int iSize = 0;
int res = 0;
MYSQL_ROW row;
MYSQL_RES *result;
mysql_query(&g_sqlCon, "SET NAMES GBK");
CString SqlValues = _T("");
SqlValues.Format(_T("select PASSWORD from master_user where USER_ID='%s';"),loginid);
iSize = WideCharToMultiByte(CP_ACP, 0, SqlValues, -1, NULL, 0, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, SqlValues, -1, update_server, iSize, NULL, NULL);
res = mysql_query(&g_sqlCon, update_server); result = mysql_use_result(&g_sqlCon);
row = mysql_fetch_row(result);
if(row[0] == password)
{
SYSTEMTIME time;
GetLocalTime(&time);
CString jobtime;
jobtime.Format(_T("%d-%02d-%02d %d:%d:%d"),time.wYear,time.wMonth,time.wDay,time.wHour,time.wMinute,time.wSecond);
SqlValues = _T("");
SqlValues.Format(_T("update master_user set LASTLOGIN_IP = '%s', LASTLOGIN_DATETIME = '%s' where USER_ID = '%s';"),(GetLocalIPAddress()?g_get_localIP:_T("127.0.0.0")),jobtime,loginid);
memset(update_server, NULL, 200);
iSize = WideCharToMultiByte(CP_ACP, 0, SqlValues, -1, NULL, 0, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, SqlValues, -1, update_server, iSize, NULL, NULL);
res = mysql_ping(&g_sqlCon); res = mysql_query(&g_sqlCon, update_server); }
else
{
AfxMessageBox(_T("PASSWORD error"));
GetDlgItem(IDC_EDIT_PASSWORD)->SetWindowText(_T(""));
}
}
res = mysql_ping(&g_sqlCon);//return 1 FAIL
res = mysql_query(&g_sqlCon, update_server);//return 1 FAIL
I didn't know why FAIL was returned?
Or teach me how to use mariaDB in MFC?
Thank you very much!