Raised This Month: $51 Target: $400
 12% 

[BETA] SQL: Mysql Server has gone away. FIXED. ADDED: Psychostats Module 26/5/10


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
2inspyr
SourceMod Donor
Join Date: Dec 2004
Old 04-12-2010 , 07:37   [BETA] SQL: Mysql Server has gone away. FIXED. ADDED: Psychostats Module 26/5/10
Reply With Quote #1

***********************
PHP FIX - WORKING BETA
***********************
PHP Code:
/*
GUNGAME PHP SQL v2.0(for gungame 2.13 beta) By Bonkaz aKa 2inspyr 

Massive credit to KRIM for the original version and parts of his code which i used.

Gungame PHP SQL is free software;
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation.

*/ 
you need 2 have the tables setup in your database for this to work, this is only a bridge between the gungame.stats file and your database. Edit the config file to suit your settings, upload to a webserver, IMPORTANT: make sure that whatever folder these file are in is CHMOD 777, if you upload it in its current structure to your public_html it will work as is, but the public will have access to execute the php file. It needs to be setup somewhere public dont have access to and run with CRON to make it secure.

ADDED PSYCHOSTATS MODULE BETA 1.0 26/5/10

for this to work correctly, you will need to have a current installation of psychostats (tested on 3.2 nightly). your gungame tables should be in the same database as your psychostats, this module will use the config from psychostats to connect to the database. upload the files in thier current structure, this will work with the "default" and "default-blue" themes currently.
it will also add a new link "gungame" to the link bar at the top so you can access the ranks.

preview can be seen here on my psychostats
http://www.gigabitgaming.com/ggstats/gungame.php CURRENTLY OFFLINE FOR UPDATING

future:
i will add the gungame rank into the users pages as well as having thier rank displayed on a main page. i might also intergrate it into the main "ranks" page.


********************
AMXX CODE FIX
********************

this code seems to be doing the job.

this is what ive modified:

PHP Code:
stock SQL_ExecuteAndLog(Handle:queryHandle,const queryStr[]=""

    if(!
SQL_Execute(queryHandle)) 
    { 
        static 
error[256]; 
        new 
errnum SQL_QueryError(queryHandle,error,255); 
         
        if(
queryStr[0]) 
        {  
            
log_amx("Could not execute query [%s] -- err #%i [%s]",queryStr,errnum,error); 
        } 
        else 
        { 
            
SQL_GetQueryString(queryHandle,mkQuery,255); 
            
log_amx("Could not execute query [%s] -- err #%i [%s]",mkQuery,errnum,error); 
        } 
         
         
        if(
errnum == 2006)  
        { 
            new 
host[32], user[32], pass[32], dbname[32]; 
            
get_pcvar_string(gg_sql_host,host,31); 
            
get_pcvar_string(gg_sql_user,user,31); 
            
get_pcvar_string(gg_sql_pass,pass,31); 
            
get_pcvar_string(gg_sql_db,dbname,31); 
             
             
            new 
sqlErrorCodesqlError[1024]; 
             
            
tuple SQL_MakeDbTuple(host,user,pass,dbname); 
             
            if(
tuple
            { 
                
db SQL_Connect(tuple,sqlErrorCode,sqlError,1023); 
            } 
             
            if(
db == Empty_Handle
            { 
                
log_amx("Could not connect to database. Error #%i: %s",sqlErrorCode,sqlError); 
                return 
0
            } 
            else 
            { 
                
SQL_Execute(queryHandle
                
log_amx("Error #%i : Reconnected : Resent query [%s]",errnum,queryStr); 
                return 
1
            } 
             
             
        } 
        else 
        { 
            return 
0
        } 
    } 
    return 
1

Original:
PHP Code:
stock SQL_ExecuteAndLog(Handle:queryHandle,const queryStr[]="")
{
    if(!
SQL_Execute(queryHandle))
    {
        static 
error[256];
        new 
errnum SQL_QueryError(queryHandle,error,255);

        if(
queryStr[0]) log_amx("Could not execute query [%s] -- err #%i [%s]",queryStr,errnum,error);
        else
        {
            
SQL_GetQueryString(queryHandle,mkQuery,255);
            
log_amx("Could not execute query [%s] -- err #%i [%s]",mkQuery,errnum,error);
        }

        return 
0;
    }
    return 
1;

basically it allows the plugin to reconnect to the database if it throws the "mysql database has gone away" error and resend the command it failed on, and send the rest through as your now reconnected.
download compiled or uncompiled version below.



cheers
2inspyr
Attached Files
File Type: zip gg_php.zip (2.1 KB, 238 views)
File Type: sma Get Plugin or Get Source (gungame_with_sql.sma - 929 views - 278.3 KB)
File Type: zip Gungame Psychostats Module beta v1.0.zip (5.4 KB, 195 views)
__________________
hmmms........

Last edited by 2inspyr; 08-01-2010 at 00:42.
2inspyr is offline
2inspyr
SourceMod Donor
Join Date: Dec 2004
Old 04-12-2010 , 08:19   Re: [BETA]sql not working????
Reply With Quote #2

[UPDATE `gg_streaks` SET streak=streak+1 WHERE type='0C' AND serverip='118.127.28.46:27050';] -- err #2006 [MySQL server has gone away]

L 04/12/2010 - 22:10:14: [gungame_with_sql.amxx] Could not execute query [SELECT wins,points,streak,wins_tp,points_tp,streak_t p FROM `gg_stats` WHERE authid='STEAM_0:0:27045047' AND serverip='118.127.28.46:27050' LIMIT 1;] -- err #2006 [MySQL server has gone away]

found the errors... i got this for everything it tries to do...

ok apprently its because the query size is 2 large. my webserver had the memory and data limit of mysql set to low for this plugin to run. after further readsing it owuld take the plugin to reconnect for every query made to the database :S im trying to get them to change the limits.
__________________
hmmms........

Last edited by 2inspyr; 04-12-2010 at 08:52.
2inspyr is offline
2inspyr
SourceMod Donor
Join Date: Dec 2004
Old 04-13-2010 , 08:56   Re: [BETA]sql not working????
Reply With Quote #3

ok so it seems its timing out, is there anyway to send a ping request to the mysql server to keep the conneciton alive???
__________________
hmmms........
2inspyr is offline
hostingguy
Member
Join Date: Jan 2008
Old 05-05-2010 , 15:04   Re: [BETA]sql not working????
Reply With Quote #4

Im having the same problem

Additionally in my case looking through the logs I do not see anything that is attempting to do an insert statement into the DB, only select update and delete - so Im not sure how the data is ever supposed to get populated in the first place - but none the less, every query/statement is getting the same error.

I use this same database and server (different tables) for other plugins and do not have this problem
hostingguy is offline
2inspyr
SourceMod Donor
Join Date: Dec 2004
Old 05-07-2010 , 06:58   Re: [BETA]sql not working????
Reply With Quote #5

yeah it times out, my database tables get written so i know the connection is fine, but because the plugin sits for a long time before sending a command the connection times out and it doesnt reconnect, im going to find a work around for this... maybe check the connection before sending the commands, or finding a way to ping the mysql server to keep the connection alive.
__________________
hmmms........
2inspyr is offline
2inspyr
SourceMod Donor
Join Date: Dec 2004
Old 05-08-2010 , 11:13   Re: [BETA]sql not working????
Reply With Quote #6

PHP FIX

ok ive written up a work around for this for those people wish to view thier gungame stats via a webpage, but cant run the gunegame sql, or it lags on them. Thanks to KRIM for saving me sometime by having already made a php script for the old sql. I have edited this to work with the new database format in 2.13beta, and also made it alot more user friendly.

in his previous version you needed to have http access to your gameserver aswell as having a webserver, not anymore. This version works on the same principal as psychostats, it will connect via ftp, download the gungame.stats file and update your database accordingly. I am about 90% finished the whole project with also includes a module for psychostats which i have made to view everythig in there. you can have a look at my progress at:

www.gigabitgaming.com/ggstats

in the links bar there is a link to my gungame stats, only thing i have left to do is get the pagination working correctly, then tidy up some code, and i will release it. you can quite obviously use this php script with cron as i do and your gungame stats are updated every X mins or whatever you like. the only thing you dont get is the ability to make a custom winner_motd.

cheers
2inspyr
__________________
hmmms........

Last edited by 2inspyr; 05-09-2010 at 05:17.
2inspyr is offline
hostingguy
Member
Join Date: Jan 2008
Old 05-08-2010 , 19:25   Re: [BETA]sql not working????
Reply With Quote #7

when I rewrote the mysql functions for uwc3 I made it open the connection and close it right away and only use it when it needed it and it worked pretty well. Since this is really only needed at the end of the round why not open the conection, update/insert each player in a loop and then close teh connection before the plugin allows the map to change.
hostingguy is offline
2inspyr
SourceMod Donor
Join Date: Dec 2004
Old 05-08-2010 , 23:37   Re: [BETA]sql not working????
Reply With Quote #8

i have tried that with no luck, i made it open open the connection for every query, and mit lags the server out so bad that it couldnt even change maps. i guess i could go a step further and only connect if the connection is closed. Without a ping function i guess i would have to send a dummy query and check the returned result to see if the conneciton is alive. otherwise, i could write a set_task to send a dummy query every x seconds to keep the conneciton alive, and if its dead then reconnect, and i could easily write a cvar for the set_task time. i.e my webservers timeout is 20secs, your might be 60, i could make a cvar to add to the gungame.cfg so you can set it as needed.
__________________
hmmms........
2inspyr is offline
Old 05-09-2010, 00:37
2inspyr
This message has been deleted by 2inspyr. Reason: added to 1st post
Old 05-09-2010, 01:00
2inspyr
This message has been deleted by 2inspyr. Reason: added 2 1st post
Old 05-15-2010, 09:33
2inspyr
This message has been deleted by 2inspyr. Reason: added everything into 1st post
jarmenz
Member
Join Date: Feb 2011
Location: Riga, Latvia
Old 03-01-2011 , 07:37   Re: [BETA] SQL: Mysql Server has gone away. FIXED. ADDED: Psychostats Module 26/5/10
Reply With Quote #9

I looked at your code and finally understood where to start. You actually saved me a lot of time doing reverse engineering with psychostats. The problem is that they closed access to their forum do to hacking attempt.

What I did, I edited the PS core file, duplicated the get_players function and used a LEFT JOIN with gg_stats. And now I have stats which can be sorted just like Players statistics in psychosts
__________________
"We view the distant peaks which are our destination with enthusiasm but actually that destination is achieved by the drudgery of single footsteps."
Geoff Burch
jarmenz is offline
gui1porpis
Member
Join Date: Jan 2009
Location: Brodowski, SP, Brazil
Old 03-24-2011 , 21:03   Re: [BETA] SQL: Mysql Server has gone away. FIXED. ADDED: Psychostats Module 26/5/10
Reply With Quote #10

I am in error in PsychoStats:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/storage/d/4f/37/cfbcs/public_html/rank/servidor2/rank/gungame.php on line 24

I tried this line in gungame.php and found this:
$total_svr_plrs = mysql_num_rows($total_plrs);

How To Fix?
__________________
gui1porpis is offline
Send a message via MSN to gui1porpis Send a message via Skype™ to gui1porpis
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:16.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode