⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmysqlconnection.cpp

📁 一个简单的mysql c api的c++ wrapper库代码
💻 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 + -