[C++] Mysql_query() funkció

Indította Pisti95, 2018-05-10, 14:39:49

questlua_game.cpp-t megnyitod!

elejére írod ezt:

////mysql////

#include "db.h"



Rákeresel erre:

int game_web_mall(lua_State* L)


Alá írod ezt:

////////mysql///////
int game_mysql_query(lua_State* L)
{
//MYSQL_FIELD *field;
SQLMsg* run = DBManager::instance().DirectQuery(lua_tostring(L,1));
MYSQL_RES* res=run->Get()->pSQLResult;
if (!res){
lua_pushnumber(L, 0);
return 0;
}
MYSQL_ROW row;
lua_newtable(L);
int rowcount = 1;
while((row = mysql_fetch_row(res))){
lua_newtable(L);
lua_pushnumber(L, rowcount);
lua_pushvalue(L, -2);
lua_settable(L, -4);
unsigned int fields = mysql_num_fields(res);
for(unsigned int i = 0; i < fields; i++){
lua_pushnumber(L, i + 1);
lua_pushstring(L, row[i]);
lua_settable(L, -3);
}
lua_pop(L, 1);
rowcount++;
}
return 1;
}
//////////////////////////////////////////////



A 'void RegisterGameFunctionTable()' táblába pedig beírod a listába:

/////mysql/////
{"mysql_query", game_mysql_query },
/////////////////////////////////



Üdv, Pisti95