2013martin1212 Posted September 10, 2015 Share Posted September 10, 2015 How i can be save a player data into sql ? I saw the sql tutorial, but i am not that good at english local connection = dbConnect("sqlite" , "database.db" ) addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource() ), function () local queryHandle = dbQuery ( connection, "CREATE TABLE IF NOT EXISTS players (id INT, name TEXT, money INT)") end ) addEventHandler ( "onPlayerQuit", root, function () executeSQLQuery("SELECT money FROM players WHERE name=?", source) local money = getPlayerMoney(thePlayer) executeSQLQuery("UPDATE players SET 'money' =? WHERE 'name'=?", money, source) end ) addEventHandler("onPlayerLogin", root, function() end ) but i am stock at now please help with the explain thanks Link to comment
JR10 Posted September 10, 2015 Share Posted September 10, 2015 You can't use executeSQLQuery (which only operates on registry.db) with dbConnect. On quit, you shouldn't be selecting data from the database since you only want to update. Also, use dbExec when you don't want to return any data. You should get the player's name to match it with the database row. addEventHandler ( "onPlayerQuit", root, function () local money = getPlayerMoney(thePlayer) executeSQLQuery("UPDATE players SET 'money' =? WHERE 'name'=?", money, getPlayerName(source)) end ) If this is all your code, then you're not inserting at all. You have to insert in order for update to update the rows. Perhaps on registering. Link to comment
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