📄 cmysqlconnection.cpp
字号:
// CMySQLConnection.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "CMySQLConnection.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
CMySQL mysql;
BOOL res = mysql.OpenConnection("localhost","root","");
if(!res)
{
printf("%s",(LPSTR)(LPCSTR)mysql.GetMySqlError());
return 0;
}
res = mysql.SelectDatabase("test");
if(!res)
{
printf("%s",(LPSTR)(LPCSTR)mysql.GetMySqlError());
return 0;
}
MYSQL_RES *result = mysql.GetQueryResult();
printf("Rows: %d\n", mysql.GetQueryRowsNumber(result));
MYSQL_ROW row;
while( ( row = mysql.MySQLFatchResult(result)) != NULL )
{
printf("id: %s, val: %s\n",(row[0] ? row[0] : "NULL"),(row[1] ? row[1] : "NULL"));
}
mysql.FreeQueryResult(result);
mysql.CloseConection();
}
return nRetCode;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -