Click here to Skip to main content
15,896,278 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,all my friends!

Recently,I learn mariaDB database.
plz check following codes:

C++
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);//return 0 Success
	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);//return 1 FAIL
		res = mysql_query(&g_sqlCon, update_server);//return 1 FAIL
	}
	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!
Posted
Comments
Sergey Alexandrovich Kryukov 13-Nov-13 20:06pm    
You rather need to teach yourself separation of concerns. What, tell me please, is the difference what UI is that, for a database?..
—SA
aolin.wang 13-Nov-13 20:58pm    
hi,i don't know why result was fail when the second sentence was sent?
Sergey Alexandrovich Kryukov 13-Nov-13 22:25pm    
Where is the second sentence?
—SA
aolin.wang 13-Nov-13 22:39pm    
update master_user set LASTLOGIN_IP = '%s', LASTLOGIN_DATETIME = '%s' where USER_ID = '%s';
it is.
chaau 14-Nov-13 0:59am    
I do not have MySQL admin console on this PC, but if I had the first thing I tried was to try to connect to "109.130.15.111" using "pesystem","tstcpe" credentials. Are you sure you want to post this information on the Internet?

1 solution

C++
SqlValues.Format(_T("select LOCK_FLAG 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);
while(row = mysql_fetch_row(result))
	temp = row[0];
mysql_free_result(result);


while(row = mysql_fetch_row(result)) temp = row[0];//it is ok!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900