1. Post #161
    SmoothieSG-1's Avatar
    May 2007
    23 Posts
    Is this working well? i'm kind noob at such things as this??

  2. Post #162
    labalicious's Avatar
    March 2006
    9 Posts
    Fucking. Awesome. You rule Andy. King'ed.

  3. Post #163
    Gold Member
    Robbis_1's Avatar
    July 2005
    344 Posts
    This is just great! I noticed a big bug though. When it tries to fetch a NULL value it just crashes. This is a quite big problem here, I hope you can find the problem that's causing this...

  4. Post #164
    GMod Illuminati
    andyvincent's Avatar
    January 2005
    65 Posts
    Robbis_1 posted:
    This is just great! I noticed a big bug though. When it tries to fetch a NULL value it just crashes. This is a quite big problem here, I hope you can find the problem that's causing this...
    If you can give me a minimal database setup and script that causes the error, I'll try and fix it over my Christmas break.

  5. Post #165
    Gold Member
    Robbis_1's Avatar
    July 2005
    344 Posts
    andyvincent posted:
    If you can give me a minimal database setup and script that causes the error, I'll try and fix it over my Christmas break.
    Alright, here's an export, I've cut down the database, but it should still work (unless I removed something I shouldn't remove):
    -- phpMyAdmin SQL Dump
    -- version 2.11.1
    -- http://www.phpmyadmin.net
    --
    -- Host: localhost
    -- Generation Time: Dec 19, 2007 at 02:16 PM
    -- Server version: 5.1.22
    -- PHP Version: 5.2.2
    
    SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
    
    --
    -- Database: `sourcebans`
    --
    
    -- --------------------------------------------------------
    
    --
    -- Table structure for table `sb_admins`
    --
    
    CREATE TABLE IF NOT EXISTS `sb_admins` (
      `aid` int(6) NOT NULL AUTO_INCREMENT,
      `user` varchar(64) NOT NULL,
      `authid` varchar(64) NOT NULL DEFAULT '',
      `password` varchar(128) NOT NULL,
      `gid` int(6) NOT NULL,
      `email` varchar(128) NOT NULL,
      `validate` varchar(128) NOT NULL,
      `extraflags` int(10) NOT NULL,
      `immunity` int(10) NOT NULL DEFAULT '0',
      `srv_group` varchar(128) DEFAULT NULL,
      `srv_flags` varchar(64) DEFAULT NULL,
      `srv_password` varchar(128) DEFAULT NULL,
      PRIMARY KEY (`aid`),
      UNIQUE KEY `user` (`user`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=56 ;
    
    --
    -- Dumping data for table `sb_admins`
    --
    
    INSERT INTO `sb_admins` (`aid`, `user`, `authid`, `password`, `gid`, `email`, `validate`, `extraflags`, `immunity`, `srv_group`, `srv_flags`, `srv_password`) VALUES
    (1, 'Killer HAHA', 'STEAM_0:0:123456', '', -1, 'NULL', '0', 1106705, 0, 'Server Admin', '', ''),
    (0, 'CONSOLE', 'STEAM_ID_SERVER', '', 0, '', '', 0, 0, NULL, NULL, NULL);

    Here's the code I was using:
    	-- Connect (this works just fine)
    	local Database, Error = mysql.connect(Host, Username, Password, DatabaseName)
    	if (Database == 0) then print("MySQL ERROR: " .. Error) return end
    
    	-- Get the whole admin/member table
    	-- THIS IS WHERE IT FAILS, Doesn't even print error
    	local Members, Working, Error = mysql.query(Database, "SELECT `authid`,`srv_group` FROM `sb_admins`")
    	if (not Working) then print("MySQL ERROR: " .. Error) return end
    	
    	-- More unrelated code...

    Alright, so when I tried changing the srv_group of CONSOLE to something else than NULL, it worked just fine.

  6. Post #166
    PC Camp's Avatar
    July 2007
    363 Posts
    I want to use this to have global CVARS on my servers. Is it possible to use player stats on the two servers I have?

    Also, is there such things as a good tutorial on how to use this? Thank you

  7. Post #167
    GMod Illuminati
    andyvincent's Avatar
    January 2005
    65 Posts
    Updated!

    Changes:
    [list][*]Fixed a bug handling NULL entries within the database.[/list]Downloads:
    [list][*]Zip file[*]Source code (for the paranoid)[/list]

  8. Post #168
    Gold Member
    DarkSpider's Avatar
    July 2006
    816 Posts
    Thanks very much man you are awesome

  9. Post #169
    loc
    loc's Avatar
    October 2005
    10 Posts
    How can I get the last inserted Primary Key? From PHP I'm used to something like $mysql->last_insert_id()

  10. Post #170
    GMod Illuminati
    andyvincent's Avatar
    January 2005
    65 Posts
    Currently you can't. I'll add it in.

  11. Post #171
    loc
    loc's Avatar
    October 2005
    10 Posts
    Ok, thank you.

  12. Post #172
    GMod Illuminati
    andyvincent's Avatar
    January 2005
    65 Posts
    Done!

    Changes
    [list][*]1.8 - 8th January 2008
    [list][*]Added mysql.last_insert_id() to get the last ID used by an AUTO_INCREMENT field.[/list][/list]
    Usage
    mysql.last_insert_id(database)
    Description: Retrieves the last ID used by an AUTO_INCREMENT_FIELD in an INSERT statement.
    Returns: number and error message. If number is false, the function failed (for whatever reason).
    Example:
    local test,error = mysql.last_insert_id(db);
    if (not test) then Msg(error .. "\n") 
    else then Msg( "Last id = " .. tostring(test) ) end
    

    Downloads
    [list][*]Zip file[*]Source code (for the paranoid)[/list]

  13. Post #173

    July 2007
    12 Posts
    Neeto. Thank you much :D

    Is there a tutorial anywhere on how to use this and MySQL? I have a MySQL database, but I do not know how to use it. Thank you.

  14. Post #174
    loc
    loc's Avatar
    October 2005
    10 Posts
    That was fast! Thanks.

  15. Post #175
    Gold Member
    dvondrake's Avatar
    August 2006
    2,329 Posts
    This doesn't work for me in the new Gmod--it keeps saying "ERROR! Module 'mysql' not found!"
    It's on a dedicated server, if that makes any difference.

    Edit:

    Ah, I see. Binary modules don't load from addons, so you have to put them in the lua folder manually.

  16. Post #176
    Ben Build's Avatar
    December 2007
    11 Posts
    dvondrake posted:
    This doesn't work for me in the new Gmod--it keeps saying "ERROR! Module 'mysql' not found!"
    It's on a dedicated server, if that makes any difference.

    Edit:

    Ah, I see. Binary modules don't load from addons, so you have to put them in the lua folder manually.
    I have the same problem!

  17. Post #177
    Gold Member
    Robbis_1's Avatar
    July 2005
    344 Posts
    Ben Build posted:
    I have the same problem!
    The libmySQL.dll should be at the same place as before.
    Go to gm_mysql\lua\ in the addon that you downloaded and cut the 2 dll files. Paste them in \garrysmod\lua\includes\modules. That will make it work. You can remove the addon now, because it just contain an example now.

  18. Post #178
    DarkCybo1's Avatar
    August 2005
    143 Posts
    I'm on a dedicated server, and I cannot get this module to work. I put the libmySQL.dll in the folder outside garrysmod where the HL2.exe is normally. I put the two dlls in the lua/includes/modules folder (not addons!) and it does not work.

    In server console, I do: "lua_run require( "mysql" )", and it just tells me it cannot find the mysql module.

    It HAS worked before the update though.

    Whaddup with this.

  19. Post #179
    Gold Member
    Looter's Avatar
    July 2005
    543 Posts
    DarkCybo1 posted:
    I'm on a dedicated server, and I cannot get this module to work. I put the libmySQL.dll in the folder outside garrysmod where the HL2.exe is normally. I put the two dlls in the lua/includes/modules folder (not addons!) and it does not work.

    In server console, I do: "lua_run require( "mysql" )", and it just tells me it cannot find the mysql module.

    It HAS worked before the update though.

    Whaddup with this.
    Same here.

  20. Post #180
    loc
    loc's Avatar
    October 2005
    10 Posts
    Yeah. The same for me.
    Seems not to load anything.

    Edit:
    Forget about it. I did just use the wrong folder. Everything works fine now.

  21. Post #181
    Chatman's Avatar
    August 2005
    6 Posts
    Is it possible to add a function called mysql_num_rows ? I need it or is there another way to check if there is someone already in a Database and if not that he create an insert for the user ?

  22. Post #182
    loc
    loc's Avatar
    October 2005
    10 Posts
    Can't you use "SELECT count(*) as total FROM [...] WHERE [...]" and then check if total is "0" or "1"?

    Edit:

    Something more I miss, is a option to change the charset.
    Like: http://de2.php.net/manual/en/functio...et-charset.php

  23. Post #183
    Gold Member
    DarkSpider's Avatar
    July 2006
    816 Posts
    http://www.xaprb.com/blog/2005/09/25...ries-in-mysql/

    basically it is
    Code:
    INSERT IF NOT EXISTS INTO table (something,somethingmore) VALUES(1,2)
    The only problem i notice is that by going that route, you can't really tell if there is a record or not. If you need to i think this would work
     
    local stuffhere,succ,isok = mysql.Query(connectionid,"SELECT index from table where steamid="..ply:SteamID())
    if !stuffhere[1][1] then
    --create stuff
    else
    --user does exist so do something else(load?)
    end
    



    if i used a BEGIN statement and then a COMMIT statement after like 40 queries in a for loop, would that improve performance because it seems to lock up the server for about 10 seconds

    Also, say you had this
    	local savestuff = gdatabase.Query("BEGIN",3)
    	local savestuff = gdatabase.Query("UPDATE table SET nonexistantcolumn='something'",3)
            local savestuff = gdatabase.Query("UPDATE table2 SET existingcolumn='something'",3)
    	local savestuff = gdatabase.Query("COMMIT",3)
    
    
    Would both of the above queries fail? if not do i just put in a commit afterwards like

    if succ then commit end

  24. Post #184
    Hates php
    high's Avatar
    May 2006
    2,413 Posts
    Still can't use the dll after the update.

    Says it doesn't exist when it does.

  25. Post #185
    Gold Member
    Neico's Avatar
    October 2005
    100 Posts
    high posted:
    Still can't use the dll after the update.

    Says it doesn't exist when it does.
    did you make sure to put the dll into garrysmod\lua\includes\modules instead of the one in the addons folder?

  26. Post #186
    Hates php
    high's Avatar
    May 2006
    2,413 Posts
    Neico posted:
    did you make sure to put the dll into garrysmod\lua\includes\modules instead of the one in the addons folder?
    Yes, I compared its path to where it said it didn't exist and they were the same. I am guessing this error is because the dll is still built for the old system and it can't be found be cause it errors on load.


    Can you please update andy.

  27. Post #187
    Gold Member
    Neico's Avatar
    October 2005
    100 Posts
    high posted:
    Yes, I compared its path to where it said it didn't exist and they were the same. I am guessing this error is because the dll is still built for the old system and it can't be found be cause it errors on load.


    Can you please update andy.

    works just fine and that it isn't compiled with the newest Interface doen't mean it won't work since garry made it so that all older versions still works wich they do very fine so the problems is on your side not on the modules one maybe you can give out some extented error messages like what path it search und where relative to it the module is

  28. Post #188
    Hates php
    high's Avatar
    May 2006
    2,413 Posts
    Neico posted:
    works just fine and that it isn't compiled with the newest Interface doen't mean it won't work since garry made it so that all older versions still works wich they do very fine so the problems is on your side not on the modules one maybe you can give out some extented error messages like what path it search und where relative to it the module is
    Everything is on my C:\.

    Also it gives the same error with the test.lua in the addons.

    Also that other dll is in

    "C:\Program Files\Steam\steamapps\high6\garrysmod\garrysmod\"

    Also I have .net framework 1.1, 2.0 and 3.5.

  29. Post #189
    tomato3017's Avatar
    April 2007
    116 Posts
    high posted:
    -snip-
    Works fine for me. You must of installed something wrong.

  30. Post #190
    Hates php
    high's Avatar
    May 2006
    2,413 Posts
    tomato3017 posted:
    Works fine for me. You must of installed something wrong.
    Well I posted above that it is in the right area...

    edit: Whooops! I put the lib dll in the wrong folder so it was failing to load.

    Sorry, my bad.

  31. Post #191
    Gold Member
    Neico's Avatar
    October 2005
    100 Posts
    high posted:
    Well I posted above that it is in the right area...

    edit: Whooops! I put the lib dll in the wrong folder so it was failing to load.

    Sorry, my bad.
    Ok so to explain it right i use your folder name to show it right:

    C:\Program Files\Steam\steamapps\high6\garrysmod\libmysql.dll
    C:\Program Files\Steam\steamapps\high6\garrysmod\garrysmod\lu a\includes\modules\<gmsv_mysql.dll | gmcl_mysql.dll | gm_mysql.dll>

    since you can load the module in those 3 ways:
    gmsv for server module
    gmcl for client module
    gm for shared module wich is the common way since mysql has no different content for client and server but oh well andy used the sv cl way

    if it now works then congratulation :D

  32. Post #192
    Battle Bott's Avatar
    November 2005
    21 Posts
    Well, it seems that escaping nil causes the game to instantly crash, or something.

    I have some code like this:
    	for col in pairs(bbb.databaselayout.users) do
    		file.Write("debug.txt","Begin col pairs. Data: "..tostring(data[col]))
    		query=query.." "..col.."=\""..bbb.escape(data[col]).."\","  //column="data", 
    	end

    (The file.write is debugging it, when you can't see any console output because it crashes as soon as I load the script. I had to reload the game about 10 times to find the bug!)

    But after I traced the error, the debug.txt file contained this:
    Code:
    Begin col pairs. Data: nil
    bbb.escape is a simple function,
    function bbb.escape(input)
    	return mysql.escape(bbb.db,input)
    end

    Could mysql.escape cause crashes if passed a nil value?

  33. Post #193

    March 2008
    7 Posts
    this dont work now

  34. Post #194

    March 2008
    7 Posts
    anybody have any success with this? put the files in every folder and still nothing.

  35. Post #195
    kevkev's Avatar
    April 2007
    1,093 Posts
    AviZ posted:
    anybody have any success with this? put the files in every folder and still nothing.
    lua/includes/modules

  36. Post #196

    March 2008
    7 Posts
    done that....

    Edit:

    C:\Program Files\Steam\steamapps\USERNAME\garrysmod\libmysql. dll
    C:\Program Files\Steam\steamapps\USERNAME\garrysmod\garrysmod \lua\includes\modules\

    this is what i have done and get failed connection, i am using this with uban on ulx


    Global ban failed! See server console for error.
    AviZ: !gban AviZ 5 "test this"

  37. Post #197
    loc
    loc's Avatar
    October 2005
    10 Posts
    @andy:
    Did you over see my last post?
    loc posted:
    Something more I miss, is a option to change the charset.
    Like: http://de2.php.net/manual/en/functio...et-charset.php

  38. Post #198
    Gold Member
    Sc00by22's Avatar
    August 2007
    1,253 Posts
    Link isn't working

  39. Post #199
    Gold Member
    AzuiSleet's Avatar
    September 2007
    758 Posts
    Here's an alternate mysql module i've been working on.

  40. Post #200
    Gold Member
    DarkSpider's Avatar
    July 2006
    816 Posts
    So will that basically do more than 1 threaded query without dropping the connection?