• MySQL for Garry's Mod
    7 replies, posted
Okay so, I have decided that I am tired of saving my information to a .txt file I would like to learn MySQL, I have everything set up, I have created and connected to my database, I just need some leads on where to go? What GLua syntax is there for MySQL? What's an example of saving a table to MySQL then reading the table? I looked on the garry's mod wiki's, they didn't give much information I could lead from. If anyone could be kind enough to push me in the right direction? Thanks!
I'm assuming you're using mysqloo, if not, ignore this post. If so, first if you haven't already, take a good look over the thread for it. [url]http://facepunch.com/showthread.php?t=1357773[/url] Next, if you didn't do so, add this to a serverside script, it's also in that thread. [lua] require( "mysqloo" ) local db = mysqloo.connect( "123.456.789.0", "drake", "abc123", "database_name", 3306 ) function db:onConnected() print( "Database has connected!" ) local q = self:query( "SELECT 5+5;" ) function q:onSuccess( data ) print( "Query successful!" ) PrintTable( data ) end function q:onError( err, sql ) print( "Query errored!" ) print( "Query:", sql ) print( "Error:", err ) end q:start() end function db:onConnectionFailed( err ) print( "Connection to database failed!" ) print( "Error:", err ) end db:connect() [/lua] Of course, change the mySQL info. There is an example query also in the code above, try playing around with that.
[QUOTE=Jeezy;44761158]-snip-[/QUOTE] No idea what I'm using but it works! Cheers!
[QUOTE=AnonTakesOver;44761235]No idea what I'm using but it works! Cheers![/QUOTE] If it works you're using mysqloo. By the way, make sure to always escape user input inside the queries. Otherwise you may become a victim of sql injection. There's a function for mysqloo that does this, [B]db:escape( string )[/B] [url]http://en.wikipedia.org/wiki/SQL_injection[/url]
[QUOTE=Jeezy;44761258]If it works you're using mysqloo. By the way, make sure to always escape user input inside the queries. Otherwise you may become a victim of sql injection. There's a function for mysqloo that does this, [B]db:escape( string )[/B] [url]http://en.wikipedia.org/wiki/SQL_injection[/url][/QUOTE] Alrighty!, Will make sure I do this, Looking at the documentation on the forum link you gave me, I can't quite see how to save something to the servers database?
Do you know SQL syntax? If not it's not difficult to figure out how to do basic storing and retrieving. These five pages should give you a grasp on what you need to do. [url]http://www.techonthenet.com/sql/tables/create_table.php[/url] [url]http://www.techonthenet.com/sql/insert.php[/url] [url]http://www.techonthenet.com/sql/update.php[/url] [url]http://www.techonthenet.com/sql/select.php[/url] [url]http://www.techonthenet.com/sql/delete.php[/url]
No, I don't know SQL. I was hoping I could use garrysmod to learn it, you know, motivation and all that. Thanks, for the links, really helpful.
Here are the DB tutorials I have so far: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/database/_connecting_with_fallbacks_in_place.lua.html[/url] [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/database/_connecting_with_mysqloo.lua.html[/url] [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/database/_connecting_with_tmysql.lua.html[/url] [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/database/basic_queries_and_query_formats_used_to_check_for_existing_row.lua.html[/url]
Sorry, you need to Log In to post a reply to this thread.