Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[C++] Mysql_query() funkció
#1
Thumbs Up 
questlua_game.cpp-t megnyitod!

elejére írod ezt:
Code:
////mysql////

#include "db.h"


Rákeresel erre:
Code:
int game_web_mall(lua_State* L)


Alá írod ezt:
Code:
    ////////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:
Code:
            /////mysql/////
            {"mysql_query",                    game_mysql_query                },
            /////////////////////////////////


Üdv, Pisti95
[Image: 1453876818-b8928becdb9a3058b7c9ff22ccc5caf6.jpeg]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)