harryh Posted March 14, 2017 Posted March 14, 2017 (edited) Hi, I am creating this dog script. I need to get the players database number which is saved via getElementData(player element, "databaseid"). function loadPlayerInfo(thePlayer) local dbid = getElementData(thePlayer, "databaseid") getDInfo = mysql:query_fetch_assoc("SELECT * FROM dogs WHERE pID = '" ..dbid.."'") local result = mysql:free_result(getDInfo) InfoArray = result if (InfoArray == true) then elseif (InfoArray == false) then --No dog saved to DB print("No Dog In DB.") print(InfoArray) else print(InfoArray) print("Fatal Error has occured please contact administrator.") end end addCommandHandler("loaddogs", loadPlayerInfo) This always returns false when information is in the database as I cannot get the player element where thePlayer is the element. Also there is data in the MySQL database and it is correct. Thanks Edited March 14, 2017 by harryh
Moderators Citizen Posted March 14, 2017 Moderators Posted March 14, 2017 mysql:free_result doesn't return any value ! You want to fetch each row from the result by doing calls to mysql:fetch_assoc until it returns nil. function loadPlayerInfo(thePlayer) local dbid = getElementData(thePlayer, "databaseid") local result = mysql:query_fetch_assoc("SELECT * FROM dogs WHERE pID = '" ..dbid.."'") local dogs = {} if result then while true then local row = mysql:fetch_assoc( result ) if not row then break end table.insert(dogs, row) -- add the sql row to dogs list end mysql:free_result(result) -- important to prevent memory leak end if (dogs and #dogs > 0) then print("Found "..#dogs.." dog(s) for pID "..tostring(dbId)) print(dogs) else --No dog saved to DB print("No Dog In DB.") end end addCommandHandler("loaddogs", loadPlayerInfo)
harryh Posted March 14, 2017 Author Posted March 14, 2017 (edited) Thanks Edited March 14, 2017 by harryh
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now