• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua How to fetch varchar from database?

okurde

New Member
Joined
Jan 28, 2009
Messages
134
Reaction score
1
Hello, I am trying to fetch varchar from database:
Code:
   local getFlag = db.getResult("SELECT * FROM `accounts` WHERE `id` = " .. getPlayerGUID(cid) .. ";")
    if (getFlag:getDataString("name") == "12311") then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Hello Master!')
        getFlag:free()
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Hello!')
        getFlag:free()
    end


Code:
[17:26:45.703] [Error - CreatureScript Interface]
[17:26:45.703] data/creaturescripts/scripts/login.lua:onLogin
[17:26:45.708] Description:
[17:26:45.708] data/lib/004-database.lua:82: [Result:getDataString] Result not set!
[17:26:45.718] stack traceback:
[17:26:45.723]  [C]: in function 'error'
[17:26:45.723]  data/lib/004-database.lua:82: in function 'getDataString'
[17:26:45.728]  data/creaturescripts/scripts/login.lua:41: in function <data/creaturescripts/scripts/login.lua:7>

Whats the problem?
Is there maybe any way to have SQL query which get only name (not * - everything)? I think it should be more efficient
 
The account id is not the same as the player's GUID. I believe this query will work for your needs:

Code:
"SELECT `name` FROM `players` WHERE `id` = " .. getPlayerGUID(cid)
 
To get the account name you can use:

Code:
getPlayerAccount(cid)

If you really wanna fetch the account from the db tho you should use getPlayerAccountId(cid) instead of getPlayerGUID
 
Back
Top