samp-plugin-sql icon indicating copy to clipboard operation
samp-plugin-sql copied to clipboard

I am confused but you don't check out the SA-MP thread anymore so yh

Open PatrickGTR opened this issue 10 years ago • 7 comments

Original Link

http://forum.sa-mp.com/showpost.php?p=3541047&postcount=396

Question

Is there any reasons why it doesn't connect? I am just continuing a script that uses this plugin and I have never used this script + there's no more documentation of this script about the errors and other stuff.

Code

[10:48:37][info] Natives::sql_connect: Connecting to database (type = 1) samp5391:***@5.39.74.166:0/samp5391_autoarena...
[10:48:38][warning] Natives::sql_connect: Connection (conn->id = 1) failed! (error = 2003, Can't connect to MySQL server on '5.39.74.166' (10061))
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:38][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:40][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:40][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:40][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:40][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:40][warning] Natives::sql_query: Invalid connection! (conn->id = 0)
[10:48:40][warning] Natives::sql_query: Invalid connection! (conn->id = 0)```

PatrickGTR avatar Aug 03 '15 12:08 PatrickGTR

Are you sure that the server at 5.39.74.166:3306 is online and accepting outside connections (e.g. server running, no firewall, etc.)

I am no longer visiting the SA-MP forums, because I am no longer interested in it.

udan11 avatar Aug 03 '15 19:08 udan11

It's a SA-MP host and it should accept connections outside, they support MySQL.

It works perfectly when I host MySQL locally, but doesn't work if I try a paid host.

PatrickGTR avatar Aug 03 '15 20:08 PatrickGTR

I tried connecting from my laptop to that server and it gives me the same error.

ERROR 2003 (HY000): Can't connect to MySQL server on '5.39.74.166' (111)

If the MySQL server is running on the same machine try using 127.0.0.1 as IP. Also, please check the documentation of your host.

udan11 avatar Aug 03 '15 21:08 udan11

Alright, no worries on that right now. I am focused on a different problem now.

        if(GameType == ARENA) {
                    format(iString, sizeof(iString), "SELECT * FROM `arenastats` WHERE `Name` = '%s' LIMIT 1", name);
                    sql_query(sqlconnection, iString, QUERY_CACHED | QUERY_THREADED, "OnArenaStats", "rds", i, name);
                } else if(GameType == BASE) {
                    format(iString, sizeof(iString), "SELECT * FROM `basestats` WHERE `Name` = '%s' LIMIT 1", name);
                    sql_query(sqlconnection, iString, QUERY_CACHED | QUERY_THREADED, "OnBaseStats", "rds", i, name);
                }
forward OnBaseStats(Result:result, extraid, name[]);
public OnBaseStats(Result:result, extraid, name[]) {

    new Rquery [160];
    new i = extraid;

    if(!sql_num_rows(result)) {
        format(Rquery, sizeof(Rquery), "REPLACE INTO `basestats`(`Name`, `Kills`, `Deaths`, `Damage`, `Points`) VALUES ('%s','%d','%d','%.0f','%.0f')", name, StoredVariables[i][Stored_Kills], StoredVariables[i][Stored_Deaths], StoredVariables[i][Stored_Damage], StoredVariables[i][Stored_Points]);
        sql_query(sqlconnection, Rquery, QUERY_THREADED);
    } else {
        format(Rquery, sizeof(Rquery), "UPDATE `basestats` SET `Kills`= Kills + %d,`Deaths`= Deaths + %d,`Damage`= Damage + %.0f,`Points`= Points + %.0f WHERE `Name` = '%s'", StoredVariables[i][Stored_Kills], StoredVariables[i][Stored_Deaths], StoredVariables[i][Stored_Damage], StoredVariables[i][Stored_Points], name);
        sql_query(sqlconnection, Rquery, QUERY_THREADED);
    }

    foreach(new x : Player) if(Player[x][Spawned] == true) {
        if(strcmp(StoredVariables[i][Stored_Name], PNames[x], true) == 0) {
            Player[x][BasePoints] = Player[x][BasePoints] + StoredVariables[i][Stored_Points];
            Player[x][BaseSPoints] = Player[x][BaseSPoints] + StoredVariables[i][Stored_Points];
            Player[x][BaseKills] = Player[x][BaseKills] + StoredVariables[i][Stored_Kills];
            Player[x][BaseDeaths] = Player[x][BaseDeaths] + StoredVariables[i][Stored_Deaths];
            Player[x][BaseDamage] = Player[x][BaseDamage] + StoredVariables[i][Stored_Damage];

            SetTimerEx("PlayerRankCheck", 1000, false, "i", x);
            break;
        }
    }

    return 1;
}

The function OnBaseStats never gets called when the round ended, it should get called after the round has been ended and it should save to the database but it doesn't do anything, doens't even insert anything into the database.

PatrickGTR avatar Aug 03 '15 21:08 PatrickGTR

Are you sure that the query SELECT * FROM ... is executed? You can check that by viewing the log.

udan11 avatar Aug 03 '15 21:08 udan11

Indeed it is getting called but errors are showing up.

[18:06:55][debug] Natives::sql_query: Scheduling statement (stmt->id = 210, stmt->query = SELECT * FROM `arenastats` WHERE Name = '[AM]pds' LIMIT 1, stmt->callback = GetPlayerArenaStats) for execution...
[18:06:55][debug] Natives::sql_query: Scheduling statement (stmt->id = 211, stmt->query = SELECT * FROM `tdmstats` WHERE Name = '[AM]pds' LIMIT 1, stmt->callback = GetPlayerTDMStats) for execution...
[18:06:55][debug] Natives::sql_query: Scheduling statement (stmt->id = 212, stmt->query = SELECT * FROM `basestats` WHERE Name = '[AM]pds' LIMIT 1, stmt->callback = GetPlayerBaseStats) for execution...

[18:06:55][debug] ProccessTick: Executing query callback (stmt->id = 210, stmt->error = 0, stmt->callback = GetPlayerArenaStats)...
[18:06:55][debug] Natives::sql_num_rows: Retrieving the count of rows (stmt->id = 210)...
[18:06:55][debug] SQL_Worker[1]: Executing query (stmt->id = 212, stmt->query = SELECT * FROM `basestats` WHERE Name = '[AM]pds' LIMIT 1)...
[18:06:55][debug] ProccessTick: Erasing query (stmt->id = 210)...

[18:06:55][debug] ProccessTick: Executing query callback (stmt->id = 210, stmt->error = 0, stmt->callback = GetPlayerArenaStats)...
[18:06:55][debug] Natives::sql_num_rows: Retrieving the count of rows (stmt->id = 210)...
[18:06:55][debug] SQL_Worker[1]: Executing query (stmt->id = 212, stmt->query = SELECT * FROM `basestats` WHERE Name = '[AM]pds' LIMIT 1)...
[18:06:55][debug] ProccessTick: Erasing query (stmt->id = 210)...

[18:06:55][debug] ProccessTick: Executing query callback (stmt->id = 212, stmt->error = 0, stmt->callback = GetPlayerBaseStats)...
[18:06:55][debug] Natives::sql_num_rows: Retrieving the count of rows (stmt->id = 212)...
[18:06:55][debug] ProccessTick: Erasing query (stmt->id = 212)...

PatrickGTR avatar Aug 03 '15 21:08 PatrickGTR

It looks like your callback is being executed because a call to sql_num_rows is made, which is believe is the one from this line: if(!sql_num_rows(result)) {.

udan11 avatar Aug 03 '15 22:08 udan11