• Gm_MySql v1.0 - OO edition.
    824 replies, posted
  • Avatar of _nonSENSE
  • [QUOTE=infinitywrai;36164936]Recently, I experienced some problems on my MySQL server and I had to reinstall. After reinstalling and restoring backups, I recreated the user accounts I had previously, so my SMF and Wordpress sites worked. Now however, my MySQLoo scripts no longer work. Specifically, running mysqloo:connect("blah"):query("SELECT blah") is returning nil. I have double checked several times about whether my login credentials are right. Additionally, I have checked my mysql server logs and gmod server logs and found nothing. There appears to be no errors when running mysqloo:connect either. If my credentials are wrong, would mysqloo:connect:query be expected to return nil? If so then I think some better feedback would be good. Anyways, do you guys have any suggestions or possible ideas on how to debug and fix this? Thanks.[/QUOTE] Post your code. Also add this to make sure it actually doesn't error while trying to connect. [lua] databaseObject.onConnectionFailed = function(self, e) print(e) end [/lua] (Check your console).
  • Avatar of infinitywrai
  • Oh, I didn't know that you could add that parameter to database objects. Anyways, the error I get is "Couldn't connect to MySQL server on 'localhost' (10061)" I'm not sure why this is, since my websites and the gm_tmysql module can connect to the same mysql user fine. The reason I prefer mysqloo is because I need to connect to multiple databases. This code used to work fine too, until I had to reinstall my MySQL server. [lua]local databases = { smf = mysqloo.connect("localhost", "smf", "paswordhere", "smf", 3306) } for _,v in pairs(databases) do v.onConnectionFailed = function(self, e) print(e) end v:connect() end[/lua]
  • Avatar of Teddi
  • [QUOTE=infinitywrai;36171657]Oh, I didn't know that you could add that parameter to database objects. Anyways, the error I get is "Couldn't connect to MySQL server on 'localhost' (10061)" I'm not sure why this is, since my websites and the gm_tmysql module can connect to the same mysql user fine. The reason I prefer mysqloo is because I need to connect to multiple databases. This code used to work fine too, until I had to reinstall my MySQL server. [lua]local databases = { smf = mysqloo.connect("localhost", "smf", "paswordhere", "smf", 3306) } for _,v in pairs(databases) do v.onConnectionFailed = function(self, e) print(e) end v:connect() end[/lua][/QUOTE] Are you allowing external connections to connect to the db? It's not on by default but you may have configured it to be so.
  • Avatar of infinitywrai
  • WTF. I changed my localhosts to 127.0.0.1 (the same thing) and it started working. I have no idea why but at least it's fixed. The weirdest part is that everything I tested with, websites and gm_tmysql used localhost fine. I'll see whether I have remote connections enabled, although I don't see how it would affect my situation since the mysql server is local.
  • Avatar of Nexus435
  • Is there any way to return the data in the same function the query is declared in without using wait()? It seems wait() just causes the server to lag.
  • Avatar of _nonSENSE
  • [QUOTE=Nexus435;36217119]Is there any way to return the data in the same function the query is declared in without using wait()? It seems wait() just causes the server to lag.[/QUOTE] You are not supposed to use wait. Use the callback function(s) that the query object provides.
  • Avatar of lorde banana
  • [QUOTE=_nonSENSE;36222434]You are not supposed to use wait. Use the callback function(s) that the query object provides.[/QUOTE] I think he wants to return a value from the query in a function
  • Avatar of Nexus435
  • [QUOTE=Banana Lord.;36222998]I think he wants to return a value from the query in a function[/QUOTE] Yeah, I don't see any other way to do it without caching everything, which I can do, but just seems like a waste of time when tmysql can do this fine.
  • Avatar of Nexus435
  • [QUOTE=_Chewgum;36230838]query.onSucess = function(q) return callback(q:getData()) end ? or what[/QUOTE] You can't return in the onSuccess function because the function is already run by the time the query is completed.
  • After using this plugin I get error loading module 'mysqloo' from file 'c:\testserver\orangebox\garrysmod\lua\ includes\modules\gmsv_mysqloo.dll': system error 14001 That's literally all I know, I did what the instructions said also
  • Avatar of Chewgum
  • [QUOTE=Mrkrabz;36425519]After using this plugin I get error loading module 'mysqloo' from file 'c:\testserver\orangebox\garrysmod\lua\ includes\modules\gmsv_mysqloo.dll': system error 14001 That's literally all I know, I did what the instructions said also[/QUOTE] Make sure you have [url]http://www.microsoft.com/en-us/download/details.aspx?id=26368[/url] installed. If you run x64 you should probably download the x86 too.
  • Does this work on GM13 or does it need to be recompiled with the GM13 headers.
  • I tried to query something with the databaseobject:escape() but it failed, not sure if I was supposed to do it that way but here its my code: [lua] PlayerSaveInit = MySQL:query( "INSERT INTO players (`plyid`)VALUES ( " .. MySQL:escape(ply:SteamID()) .. " )" ) PlayerSaveInit.onSuccess = function() print("Inserted Data") end PlayerSaveInit:start() [/lua] but it doesn't works, its like it wasn't called at all...
  • INSERT INTO players (plyid)VALUES ( `" .. MySQL:escape(ply:SteamID()) .. "` )"
  • Avatar of Nexus435
  • [QUOTE=Banana Lord.;36529677]do you even need to escape a SteamID[/QUOTE] Yeah, no way to mysql inject with a steamid.
  • Avatar of Ruzza
  • [QUOTE=Stillnex;36528217]I tried to query something with the databaseobject:escape() but it failed, not sure if I was supposed to do it that way but here its my code: [lua] PlayerSaveInit = MySQL:query( "INSERT INTO players (`plyid`)VALUES ( " .. MySQL:escape(ply:SteamID()) .. " )" ) PlayerSaveInit.onSuccess = function() print("Inserted Data") end PlayerSaveInit:start() [/lua] but it doesn't works, its like it wasn't called at all...[/QUOTE] You're missing the quotes after VALUES ( and before the ) so should be MySQL:query( "INSERT INTO players (`plyid`) VALUES ('" .. MySQL:escape( ply:SteamID() ) .. "')" )
  • Avatar of ollie
  • I keep getting "MySQL server has gone away" error, is there any way to fix this or do i need to reconnect always when running new query?
  • Avatar of _nonSENSE
  • That is an issue with your MySQL configuration; increase the value of the [URL="http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_wait_timeout"]wait_timeout[/URL] system variable. Alternatively, you can send a query every x seconds to keep the connection open (may not work when nobody is connected). When the server closes the connection, you will need to reopen it.
  • Avatar of Ruzza
  • [QUOTE=ollie;36631319]I keep getting "MySQL server has gone away" error, is there any way to fix this or do i need to reconnect always when running new query?[/QUOTE] [lua]timer.Create( "AntiTimeout", 30, 0, function() local Query = mysql:query( "SHOW STATUS LIKE 'uptime';" ) Query:start() end )[/lua]
  • Avatar of _nonSENSE
  • [QUOTE=Ruzza;36633627][lua]timer.Create( "AntiTimeout", 30, 0, function() local Query = mysql:query( "SHOW STATUS LIKE 'uptime';" ) Query:start() end )[/lua][/QUOTE] Doesn't run if nobody is connected / has connected to the server. If your server is empty for a while after mapchange and the value of wait_timeout is set to something low (like an hour), the connection will still be closed.
  • Avatar of Teddi
  • [QUOTE=_nonSENSE;36633785]Doesn't run if nobody is connected / has connected to the server. If your server is empty for a while after mapchange and the value of wait_timeout is set to something low (like an hour), the connection will still be closed.[/QUOTE] Runs fine. I believe the old "Timers don't run when no one is connected" was changed a while ago.
  • Avatar of _nonSENSE
  • [QUOTE=Teddi Orange;36634638]Runs fine. I believe the old "Timers don't run when no one is connected" was changed a while ago.[/QUOTE] Ah, thanks for the heads up. Disregard what I said earlier then.
  • Avatar of Ruzza
  • [QUOTE=_nonSENSE;36635543]Ah, thanks for the heads up. Disregard what I said earlier then.[/QUOTE] You're welcome.
  • So i recently found out that you can do [lua] local query = MyDB:query("SELECT 1+1") query:start() query:wait() local data = query:getData() [/lua] Essentially the wait function puts the thread on hold until the query has been completed.
  • Avatar of Ruzza
  • [QUOTE=Remscar;36644215]So i recently found out that you can do [lua] local query = MyDB:query("SELECT 1+1") query:start() query:wait() local data = query:getData() [/lua] Essentially the wait function puts the thread on hold until the query has been completed.[/QUOTE] Why exactly would you want to put the thread on hold, is it to prevent multiple queries running at once?