SA-MP Forums Archive
Mysql loading - 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: Mysql loading (/showthread.php?tid=657046)



Mysql loading - KinderClans - 30.07.2018

Can someone tell me why this code doesn't work?

pawn Код:
new query[128];
    mysql_format(g_SQL, query, sizeof(query), "SELECT * FROM `BwhSafes`", "LoadxSafes");
    mysql_query(g_SQL, query);
LoadxSafes:

pawn Код:
forward LoadxSafes();
public LoadxSafes()
{
    new rows = cache_num_rows();
    new id, loaded;
    if(rows)
    {
        while(loaded < rows)
        {
            cache_get_value_name_int(loaded, "ID", id);
            cache_get_value_name_float(loaded, "X", xSafe[id][safe_Pos][0]);
            cache_get_value_name_float(loaded, "Y", xSafe[id][safe_Pos][1]);
            cache_get_value_name_float(loaded, "Z", xSafe[id][safe_Pos][2]);
            cache_get_value_name_float(loaded, "A", xSafe[id][safe_Pos][3]);

            xSafe[id][safe_Obj] = CreateObject(2332, xSafe[id][safe_Pos][0], xSafe[id][safe_Pos][1], xSafe[id][safe_Pos][2], 0.0, 0.0, xSafe[id][safe_Pos][3]);

            xSafe[id][safe_Info] = Create3DTextLabel("Type "SAMP_BLUE"/saferob "WHITE"to rob this safe.", -1, xSafe[id][safe_Pos][0], xSafe[id][safe_Pos][1], xSafe[id][safe_Pos][2]+1, 100, 0);

            Iter_Add(xSafes, id);
            loaded++;
        }
    }
    printf("%d safes have been loaded.", loaded);
    return 1;
}
It doesn't load safes stored in "BwhSafe" even if they're in the table..and i dont get the " printf("%d safes have been loaded.", loaded);" message in server console.


Re: Mysql loading - Calisthenics - 30.07.2018

"ID" is meant to be a way to identify the said record. If "ID" has been set as AUTO INCREMENT (which it should), you don't rely on them as indexes for your arrays. You've got the row id for that.
pawn Код:
cache_get_value_name_int(loaded, "ID", xSafe[loaded][safe_ID]);
cache_get_value_name_float(loaded, "X", xSafe[loaded][safe_Pos][0]);
cache_get_value_name_float(loaded, "Y", xSafe[loaded][safe_Pos][1]);
cache_get_value_name_float(loaded, "Z", xSafe[loaded][safe_Pos][2]);
cache_get_value_name_float(loaded, "A", xSafe[loaded][safe_Pos][3]);
now let's say you want to update the position to the database, you'd use:
pawn Код:
"UPDATE ... SET ... WHERE ID=%d", ..., xSafe[loaded][safe_ID]);
As for the reason you don't receive the debug message in server console is because a run time error 4 occurred so the code execution was stopped.


Re: Mysql loading - KinderClans - 30.07.2018

I don't have safe_ID. I did:

pawn Код:
cache_get_value_name_int(loaded, "ID", id);
But still doesn't work..


Re: Mysql loading - DiegoR - 30.07.2018

PHP код:
mysql_tquery(g_SQL"SELECT * FROM `BwhSafes`""LoadxSafes"); 



Re: Mysql loading - KinderClans - 30.07.2018

Same.

Mysql log:

Quote:

[21:13:11] [DEBUG] mysql_tquery(0, "SELECT * FROM `BwhSafes`", "LoadxSafes", "")
[21:13:11] [ERROR] mysql_tquery: invalid connection handle '0'
[21:13:11] [DEBUG] mysql_tquery: return value: '0'

Edit 2:

Tried to call directly LoadxSafes(); in OnGameModeInit and got this:

Quote:

[21:16:41] [DEBUG] cache_get_row_count(0x04AAA074)
[21:16:41] [ERROR] cache_get_row_count: no active cache




Re: Mysql loading - Calisthenics - 31.07.2018

Quote:
Originally Posted by KinderClans
Посмотреть сообщение
I don't have safe_ID. I did:

pawn Код:
cache_get_value_name_int(loaded, "ID", id);
But still doesn't work..
Create one. As I said to my previous post, do not use "ID" as index of array.

EDIT:
Quote:
Originally Posted by KinderClans
Посмотреть сообщение
Same.

Mysql log:



Edit 2:

Tried to call directly LoadxSafes(); in OnGameModeInit and got this:
Do you even connect to a mysql server? Also never call directly as there will be no cache.


Re: Mysql loading - GTLS - 01.08.2018

Show the code where you connect to Database.