'LinKin Posted January 26, 2014 Share Posted January 26, 2014 Hello, I want to learn how to use a MySQL database with MTA scripts. I know absolutely nothing about it so far. That's why I'm here to ask if someone is kind enough to tell me where to begin from. I was taking a look at this post https://forum.multitheftauto.com/viewtopic.php?f=148&t=42067 then found in the wiki something that said that now MySQL functions are native in MTA. (i.e dbConnect, etc). So I got kind of confused whether or not I must use that MTA-MySQL Module or not. Also, there exists any example-script that uses MySQL? I appreciate your help! -Linkin. Link to comment
Anubhav Posted January 26, 2014 Share Posted January 26, 2014 I Suggest use db functions. Use SQL Module. There examples . Go to community and search serverupdates its made by MySQL database. Link to comment
'LinKin Posted January 26, 2014 Author Share Posted January 26, 2014 https://wiki.multitheftauto.com/wiki/Modules/MySQL Isn't it suppossed that db functions were made in order to avoid using SQL Module? Link to comment
xXMADEXx Posted January 26, 2014 Share Posted January 26, 2014 https://wiki.multitheftauto.com/wiki/Modules/MySQLIsn't it suppossed that db functions were made in order to avoid using SQL Module? You shouldn't use the MySQL module, it's very out dated. Here is some stuff that might help you: http://www.w3schools.com/sql/default.as ... beebb8869c http://dev.mysql.com/doc/refman/5.0/en/tutorial.html If you want, you can take a look at my "Warp Manager" script, it uses SQLite (Pretty much the same as MySQL) to save the warps, and hopefully you can learn something from it. https://community.multitheftauto.com/ind ... ls&id=7419 Link to comment
'LinKin Posted January 26, 2014 Author Share Posted January 26, 2014 Thanks. Going a little bit forwards. I want your opinion; I think it's not nessesary to use setElementData with the values stored in a database because we could make the operations directly into it. However, I think it is better (like easier) to use this setElementData, because while a player is online, and he does some actions, we can 'play' with setElementData and getElementData. Then when he quits, we can use getElementData and store the values we want into the database. What do you think about that? Link to comment
xXMADEXx Posted January 26, 2014 Share Posted January 26, 2014 setElementData is used to store temporary data, when the player quits all of the data will be losted. With MySQL, the data will save to a remote server (or the same), so the data will be saved when the server restarts, or the player quits. Link to comment
'LinKin Posted January 26, 2014 Author Share Posted January 26, 2014 But, for example, I do something like: addEventHandler("onPlayerQuit", getRootElement, function() local wins = getElementData(source, "wins") local deaths = getElementData(source, "deaths") -- then, somehow, I store those values into the SQL db (I've not learnt the code by heart yet) end) Link to comment
xXMADEXx Posted January 26, 2014 Share Posted January 26, 2014 But, for example,I do something like: addEventHandler("onPlayerQuit", getRootElement, function() local wins = getElementData(source, "wins") local deaths = getElementData(source, "deaths") -- then, somehow, I store those values into the SQL db (I've not learnt the code by heart yet) end) Well, first you just need to make a simple MySQL/SQLite connection using dbConnect. Then, in the event you just need to do something like this: local dbc = dbConnect ( "sqlite", "mydatabase.sql" ) dbExec ( dbc, "CREATE TABLE IF NOT EXISTS stats ( Player TEXT, Wins INT, Deaths INT )" ) addEventHandler ( "onPlayerJoin", root, function ( ) dbExec ( "INSERT INTO stats ( Player, Wins, Deaths ) VALUES ( ?, ?, ? )", getPlayerName ( source ), '0', '0' ) end ) addEventHandler("onPlayerQuit", getRootElement, function() local wins = getElementData(source, "wins") local deaths = getElementData(source, "deaths") dbExec ( "UPDATE stats SET Wins=?, Deaths=? WHERE Player=?", wins, deaths, getPlayerName( source ) ) end) Link to comment
'LinKin Posted January 26, 2014 Author Share Posted January 26, 2014 Yeah, of course having a connection to a database. I almost always avoid to put some code, and just put the code where I want to focus, that's why I only implementated the code of onPlayerQuit event. Thanks again mate, you've been very helpful Link to comment
'LinKin Posted January 27, 2014 Author Share Posted January 27, 2014 Guys, when you connect to a MySQL database, according to the Wiki we must provide the username and password of the database. username: Usually required for MySQL, ignored by SQLite password: Usually required for MySQL, ignored by SQLite But... Isn't this unsafe? I mean, you're telling anyone who has your script the username and password of your MySQL database. Link to comment
tosfera Posted January 27, 2014 Share Posted January 27, 2014 Guys, when you connect to a MySQL database, according to the Wiki we must provide the username and password of the database.username: Usually required for MySQL, ignored by SQLite password: Usually required for MySQL, ignored by SQLite But... Isn't this unsafe? I mean, you're telling anyone who has your script the username and password of your MySQL database. The mysql functions are server sided, not client sided. Therefor player will not have the files with your queries nor username/password/host from your database. Link to comment
'LinKin Posted January 28, 2014 Author Share Posted January 28, 2014 They are serversided, thats why I said "anyone who has your script". For example, I was told that ON1XS' script (https://community.multitheftauto.com/in ... ls&id=2764) used a MySQL database. And that guy was sharing his script, so everyone had the seversided file; Compiled, but you know that it's possible to uncompile. Well, I don't see a point to keep discussing about this because it was a general question, I don't think to share the script I will make. Link to comment
xXMADEXx Posted January 28, 2014 Share Posted January 28, 2014 They are serversided, thats why I said "anyone who has your script".For example, I was told that ON1XS' script (https://community.multitheftauto.com/in ... ls&id=2764) used a MySQL database. And that guy was sharing his script, so everyone had the seversided file; Compiled, but you know that it's possible to uncompile. Well, I don't see a point to keep discussing about this because it was a general question, I don't think to share the script I will make. Do what I do and use the "encryption" option on the MTA compiler, nobody can decode it. https://luac.multitheftauto.com/ Or, if you really want it to be secure, you can use "callRemote" to a website php code. Link to comment
TAPL Posted January 28, 2014 Share Posted January 28, 2014 ON1XS is actually using php, proof: callRemote http:// IP % /AntiFake/mta/mta_PlayerList.php/:80 callRemote http:// IP * /AntiFake/mta/server_SerialSearch.php/:80 callRemote http:// IP ( /AntiFake/mta/server_NickSearch.php/:80 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