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

📄 cmysql.cpp

📁 mfc_mysql
💻 CPP
字号:
// Mysql.cpp: implementation of the CMysql class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "CMysql.h"

/*#include "stdafx.h"
#include "winsock.h"
#include <stdlib.h>
#include <string.h>
#include "stdio.h"
#include "mysql.h"

#include <stdio.h>
//#include "string.h"
#include <malloc.h>*/


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMysql::CMysql()
{
	mysql_init(&mysql);
}

CMysql::~CMysql()
{
	mysql_close(&mysql);
}

int CMysql::connect(char *host, char *user, char *password,char *db_name)
{
/*	char aa[]="INSERT INTO data (time,data) VALUES ('",data_string[100]="",data1[10];
	char query[]="a",*p_query,dot[]="'";
	p_query=query;
	str_link(data_string,aa);
	ltoa(*a,data1,10);
	printf("data1:%s\n",data1);
	str_link(data_string,data1);
	str_link(data_string,dot);
	p_query=",";
	str_link(data_string,p_query);
	ltoa(*b,data1,10);
	printf("data1:%s\n",data1);
	str_link(data_string,dot);
	str_link(data_string,data1);
	p_query="')";
	str_link(data_string,p_query);*/
	if(!mysql_real_connect(&mysql,host,user,password,db_name,0,NULL,0))
	{
//		printf("Failed to connect to database. Error: %s\n",mysql_error(&mysql));
		return 0;
	}
//	printf("Ok\n");
	return 1;
}

char *CMysql::str_link(char *a,char *b)
{
	char *res;
	int i=0,j=0;
	res=a;
	i=strlen(a);
	while(*b!='\0')
	{
		res[i+j]=*b;
		b++;
		j++;
	}
	res[i+j]='\0';
	return a;
}

int CMysql::query(const char *query)
{
	mysql_query(&mysql,query);
    result=mysql_store_result(&mysql);
	return 1;
}


int CMysql::get_next_row()
{
	if(row=mysql_fetch_row(result))
	{
		return 1;
	}
	return 0;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -