代码拉取完成,页面将自动刷新
同步操作将从 qykings/kgameserver 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "MySqlCenter.h"
MySqlCenter* MySqlCenter::_instance=new MySqlCenter();
MySqlCenter* MySqlCenter::GetInstance()
{
return _instance;
}
MySqlCenter::MySqlCenter(void)
{
_query=NULL;
}
MySqlCenter::~MySqlCenter(void)
{
}
int MySqlCenter::loadCof(char *filename)
{
FILE *f=fopen(filename,"rb");
if(f==nullptr)
{
std::cout<< "no file:"<<filename<<std::endl;
exit(0);
}
fseek(f,0,SEEK_END);
long len=ftell(f);
fseek(f,0,SEEK_SET);
char *data=(char*)malloc(len+1);
fread(data,1,len,f);
fclose(f);
decodeJsonStr(data);
free(data);
return 0;
}
void MySqlCenter::decodeJsonStr(char *text)
{
cJSON *json;
json=cJSON_Parse(text);
if (!json)
{
printf("mysqlcenter Error before: [%s]\n",cJSON_GetErrorPtr());
}
else
{
cJSON *c=cJSON_GetObjectItem(json,"dbUser");
memset(_dbuser,0,sizeof(_dbuser));
strcpy(_dbuser,c->valuestring);
c=cJSON_GetObjectItem(json,"dbPasswd");
strcpy(_dbpasswd,c->valuestring);
c=cJSON_GetObjectItem(json,"dbname");
strcpy(_dbname ,c->valuestring);
c=cJSON_GetObjectItem(json,"tablename");
strcpy(_tablename,c->valuestring);
c=cJSON_GetObjectItem(json,"dbIp");
strcpy(_dbip,c->valuestring);
c=cJSON_GetObjectItem(json,"port");
_port = c->valueint;
cJSON_Delete(json);
}
}
int MySqlCenter::connect(
const char *unix_socket,
unsigned long clientflag)
{
_con = mysql_init((MYSQL*) 0);
if ( _con !=NULL && mysql_real_connect(_con,_dbip,_dbuser,_dbpasswd,_dbname,_port,
unix_socket,clientflag ) )
{
if (!mysql_select_db(_con,_dbname))
{
printf("select successfully the database!\n");
_con ->reconnect = 1;
_query = "set names \'gbk\'";
//mysql_query(con,"set names \'gbk\'");
int rt=mysql_real_query(_con,_query,strlen(_query));
if (rt)
{
printf("error making query: %s !!!\n",mysql_error(_con));
}
else
{
printf("query %s succeed!\n",_query);
}
}
}
else
{
MessageBoxA(NULL,"Unable to connect the database,check your configuration!","",NULL);
return -1;
}
return 0;
}
int MySqlCenter::insert(char *tmp)
{
//注意如何向具有自增字段的数据库中插入记录
// sprintf(tmp,"insert into %s (id, name) values(%d,\"%s\")",tablename,123,"test1");
mysql_query(_con,tmp);
int rt = mysql_real_query(_con,tmp,strlen(tmp));
if (rt)
{
printf("Error insert: %s !!!\n",mysql_error(_con));
}
else
{
printf("%s executed!!!\n",tmp);
}
return 0;
}
int MySqlCenter::select(char *tmp)
{
// sprintf(tmp,"select * from %s",tablename);
int rt=mysql_real_query(_con,tmp,strlen(tmp));
if (rt)
{
printf("Error select: %s !!!\n",mysql_error(_con));
return rt;
}
else
{
printf("%s executed!!!\n",tmp);
}
return rt;
}
MYSQL_RES* MySqlCenter::getOperateResult(){
return mysql_store_result(_con);//将结果保存在res结构体中
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。