SA-MP Forums Archive
Strange error - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Strange error (/showthread.php?tid=616640)



Strange error - AndreiWow - 08.09.2016

if someone logs in after the server has been empty for a while I get this error and the server close

Код:
[14:46:59] MySQL Error (0): Could not execute query. MySQL server has gone away.
[14:46:59]  SQL: SELECT `UserID` FROM `Accounts` WHERE `Username` = 'Admin_Teller'
[14:46:59] MySQL Error (0): Function: 'mysql_store_result' called when no prior query executed.. MySQL server has gone away.



Re: Strange error - Sithis - 08.09.2016

You clearly have no database connection active. Make sure you reconnect to the database before executing a query.


Re: Strange error - venomlivno8 - 08.09.2016

Which version of MySQL plugin are you using? Did you enabled auto reconnecting?

Post some code


Re: Strange error - ThatFag - 08.09.2016

Check out your database name and script
if database name is for example UserID and in script is used as userid then it wont connect to the database they must be the same
check script and change ur database name


Re: Strange error - AndreiWow - 08.09.2016

How do I enable auto reconnecting?


Re: Strange error - Vince - 08.09.2016

There is no auto-reconnect in this extremely outdated version of the plugin. If what your signature says is true then I don't know why you still bother with such outdated stuff; new projects should use the new standards.


Re: Strange error - venomlivno8 - 08.09.2016

If what Vince said is true, then you need to make a reconnect function every 1440 seconds, since database connection is lost after 1440 seconds, and that would be like.

pawn Код:
#define MYSQL_HOST                          ""
#define MYSQL_USER                          ""
#define MYSQL_PASS                          ""
#define MYSQL_BASE                          ""

new db_handle;

forward MYSQL_Reconnect();
public MYSQL_Reconnect() {
    if(mysql_errno(db_handle)) {
        db_handle = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_BASE, MYSQL_PASS, 3306);
    }
    return 1;
}

public OnGameModeInit() {
    db_handle = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_BASE, MYSQL_PASS, 3306);
    SetTimer("MYSQL_Reconnect", 1440000, true);
    return 1;
}
you need to set values for database defines.

edit: on gamemode initiation, you connect to your database and start the reconnect timer. when timer reaches 1440 seconds(1440000ms), it checks connection, if it's not connected, then it reconnects, if it's connected then it does nothing.