• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Error in SQL syntax

gabriel28

Active Member
Joined
Mar 16, 2012
Messages
200
Solutions
6
Reaction score
25
I'm trying to do a function that get the skill value from the database, but I don't have much knowledge about sql, so I need this help. My MySQL version is 5.5


LUA:
function getSkill (cid, skill)
local pid = getPlayerGUID(cid)
db.getResult("SELECT `value` FROM `player_skills` WHERE `player_id` = " ..pid.. " and `skillid` = ".. skill ..",")
return true
end

Thanks in advance.
 
Solution
I'm trying to do a function that get the skill value from the database, but I don't have much knowledge about sql, so I need this help. My MySQL version is 5.5


LUA:
function getSkill (cid, skill)
local pid = getPlayerGUID(cid)
db.getResult("SELECT `value` FROM `player_skills` WHERE `player_id` = " ..pid.. " and `skillid` = ".. skill ..",")
return true
end

Thanks in advance.
I'm not sure what distro you are using but you can try this:
LUA:
function getSkill(cid, skill)
    local result = db.getResult("SELECT `value` FROM `player_skills` WHERE `player_id` = " .. getPlayerGUID(cid) .. " and `skillid` = " .. skill)
    if result:getID() == -1 then
        return
    end
    local skill_value = result:getDataInt('value')...
I'm trying to do a function that get the skill value from the database, but I don't have much knowledge about sql, so I need this help. My MySQL version is 5.5


LUA:
function getSkill (cid, skill)
local pid = getPlayerGUID(cid)
db.getResult("SELECT `value` FROM `player_skills` WHERE `player_id` = " ..pid.. " and `skillid` = ".. skill ..",")
return true
end

Thanks in advance.
I'm not sure what distro you are using but you can try this:
LUA:
function getSkill(cid, skill)
    local result = db.getResult("SELECT `value` FROM `player_skills` WHERE `player_id` = " .. getPlayerGUID(cid) .. " and `skillid` = " .. skill)
    if result:getID() == -1 then
        return
    end
    local skill_value = result:getDataInt('value')
    result:free()
    return skill_value
end
 
Solution
@Apollos
Thanks alot. I had headaches trying to make it work. hahah
Np bro. In case you're still curious, the error in your syntax was because you had a comma at the end, you were pretty close. Remember anytime you use a query to get a result you should always free the results.
 
Back
Top