?? cmysql.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 + -