AMARANT Posted May 20, 2012 Share Posted May 20, 2012 I want to learn more how to use SQL database within MTA. So I tried to create one when my resource starts. I used this: function createSQLOnStart (res) if res==getThisResource() then executeSQLCreateTable ( "mostwanted", "nickname TEXT, reward NUMBER, desc TEXT" ) end end addEventHandler ( "onResourceStart", getRootElement(),createSQLOnStart ) In the console it says "Creating new DB table mostwanted" so I figured that I did it right. But where that database is located on the server? Where can I see it like I do with 'internal.db'? Link to comment
Edikosh998 Posted May 20, 2012 Share Posted May 20, 2012 on the SQL Browser, load...registry.db at server/mods/deathmatch Link to comment
AMARANT Posted May 20, 2012 Author Share Posted May 20, 2012 Thanks man, I didn't know that it's there Link to comment
Alpha Posted May 20, 2012 Share Posted May 20, 2012 It's better to use the new database functions: dbConnect dbQuery dbExec dbPoll dbFree Link to comment
Maurize Posted May 20, 2012 Share Posted May 20, 2012 It's much better to create functions like "getDatabase( element, "row" ) and setDatabase( element, "row", value ) to handle database and have a smart use. if u have any questions or need help simply write a message and i will help you:) Link to comment
Edikosh998 Posted May 21, 2012 Share Posted May 21, 2012 It's better to use the new database functions: dbConnect dbQuery dbExec dbPoll dbFree Yeah, MySQL is much better. You can use XAMPP for it (localhost). But be careful, because you must use "dbPoll" to get a table data. Then, if you want to INSERT, DELETE or UPDATE something, you can use "dbExec" Link to comment
Alpha Posted May 21, 2012 Share Posted May 21, 2012 Also, I advise you to use callbacks, using dbPoll(queryHandle, -1) freezes the server. Link to comment
AMARANT Posted May 21, 2012 Author Share Posted May 21, 2012 How can I check that in my table in "nickname" column a row "AMARANT" already exists? I mean blocking possibility to add the same names to it. Link to comment
Castillo Posted May 21, 2012 Share Posted May 21, 2012 Try this: local query = dbQuery ( handler, "SELECT columnName FROM nickname WHERE columnName = ?", "AMARANT" ) local result, numrows, errmsg = dbPoll ( query, -1 ) if ( type ( result ) == "table" and #result == 0 or not result ) then return false else return true end Link to comment
AMARANT Posted May 22, 2012 Author Share Posted May 22, 2012 I did it in a different way with executeSQLQuery but thanks anyway 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