seal Posted December 12, 2013 Posted December 12, 2013 Hi, im new in lua programming and need some help in executesql using. Ok, i can create tables and rows but i cant put in values, so how can i put values into the database? E.G: playerposition, charactername. And when an account is already in the table how can is update its data? Thank you for your answers
golanu21 Posted December 12, 2013 Posted December 12, 2013 (edited) addEventHandler("onPlayerJoin", getRootElement(), function () zombie_db = connectToDB() x, y, z = getElementPosition(source) dbExec( zombie_db, "INSERT INTO characters (nume, model, health, posx, posy, posz) VALUES (?,?,?,?,?,?)", getPlayerName(source), getElementModel(source), getElementHealth(source), x, y, z ) end) take an example Edited December 12, 2013 by Guest
Castillo Posted December 12, 2013 Posted December 12, 2013 You can execute INSERT queries to add rows with values, and also UPDATE queries to update rows.
Desaster Posted December 12, 2013 Posted December 12, 2013 here are the most useful functions for sql https://wiki.multitheftauto.com/wiki/ExecuteSQLQuery to update data use UPDATE and to put values use INSERT INTO ^^
seal Posted December 12, 2013 Author Posted December 12, 2013 thanks your comments, but how do the sql knows in which line should it update? e.g: id name money 1 John 123 2 Max 50 i call update function but how can i update max's values, instead e.g john's values?
Renkon Posted December 12, 2013 Posted December 12, 2013 If you want to use UPDATE You can use WHERE statement WHERE name = 'John' WHERE id = 1
Sasu Posted December 12, 2013 Posted December 12, 2013 You can get more information here: http://www.w3schools.com/sql/sql_where.asp
seal Posted December 12, 2013 Author Posted December 12, 2013 well, i know how simple SQL query works, but how can i use "where" in MTA?
pa3ck Posted December 12, 2013 Posted December 12, 2013 If you want to use UPDATE You can use WHERE statementWHERE name = 'John' WHERE id = 1 dbExec(connection,"UPDATE character SET name = ? WHERE id = ?", getPlayerName(source), accountID) accountID is the account, which you want to update
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