Mysql loading
#1

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.
Reply
#2

"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.
Reply
#3

I don't have safe_ID. I did:

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

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

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

Reply
#6

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.
Reply
#7

Show the code where you connect to Database.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)