SQL connection ID resets - 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: SQL connection ID resets (
/showthread.php?tid=485729)
SQL connection ID resets -
[FMJ]PowerSurge - 05.01.2014
pawn Код:
static SQL:sqlconn,
Result:query;
pawn Код:
new SQL:sqlconn,
Result:query;
pawn Код:
sqlconn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS, SQL_DB);
printf("%d", sqlconn);
OnGameModeInit; sqlconn is 1 here and in the sql log file it says that it connects with connection ID 1.
I do a query at OnGameModeInit and check sqlconn again and it is 1 still:
pawn Код:
format(string, sizeof(string), "SELECT Sum(`Crack`), Sum(`Pot`), Sum(`Materials`) FROM Users");
query = sql_query(sqlconn, string);
printf("%d", sqlconn);
At OnPlayerRequestClass I do another few queries:
pawn Код:
format(string2, 512, "SELECT COUNT(*) FROM `Users` WHERE Username = '%s'", PlayerName(playerid));
query = sql_query(sqlconn,string2);
printf("%d", sqlconn);
sqlconn is now 0?
In the sql log file it says:
Код:
[21:24:20][info] Natives::sql_connect: Connecting to database (type = 1)
[21:24:20][info] Natives::sql_connect: Connection (conn->id = 1) was succesful!
[21:24:20][warning] Natives::sql_debug: Switching the log levels to (0, 3)...
[21:24:20][debug] Natives::sql_query: Executing statement (stmt->id = 1, stmt->query = SELECT Sum(`Crack`), Sum(`Pot`), Sum(`Materials`) FROM Users)...
[21:24:20][debug] Natives::sql_query: Statement executed (stmt->id = 1, stmt->error = 0). No callback found!
[21:24:53][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
The statement executed is the SELECT Sum and the warning below it is the next query I do in OnPlayerRequestClass. Nowhere in the script is sqlconn given a new value and I've tried both
new SQL: sqlconn and
static SQL: sqlconn and both reset to 0 after the first statement is executed. I haven't had this problem with the same script before, the only difference is I haven't used it in about 6 months. No changes have been made to it, either. The only difference is I'm using a static version of the plugin as I'm now on Debian 6 instead of Ubuntu. Even so, why would that change the value of sqlconn in the script?
Re: SQL connection ID resets -
[FMJ]PowerSurge - 23.01.2014
Fixed it by using the connection ID with an SQL tag rather than a variable.
pawn Код:
sql_connect(...); // connects with SQL ID 1
sql_query(SQL:1, ...);