Could not save MySQL query O.o
#1

pawn Код:
stock CreateAccountID(playerid) // To create a MySQL Database ID for the account
{
    new sqlid = PlayerInfo[playerid][pSQLID] = cache_insert_id(sqldb);
    return sqlid;
}
//
stock GetName(playerid)
{
    new AccName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, AccName, sizeof(AccName));
    return pName;
}
//
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    format(query, sizeof(query), "INSERT INTO accounts (sqlid, accname) VALUES (%i, %s)", CreateAccountID(playerid), GetName(playerid));
    mysql_query(sqldb, query);
    return 1;
}
And still on phpmyadmin samp_db table accounts is showing nothing.
Reply
#2

Change 'mysql_query(sqldb, query);' to 'mysql_query(query);'
Reply
#3

I'm using BlueG's R37 MySQL and if I change it then Compiler will show error
Reply
#4

Why not use R6 plugin?
Reply
#5

Where to start. First - using unthreaded queries will lag your server. Heavily. It looks like you are just starting development, search for tutorial (or read about ORM, it's even easier).

I am pretty sure your log should show something like "No cache active". Because you don't have any active cache. Also, your account system is weird. You are creating account on disconnect? Ok, but what if that player already has an account? You don't have to pass id to insert query, you retrieve it after execution.
Reply
#6

Misiur I am learning MySQL now(started 12 hours a go) and I'm not creating account I'm just testing my database but it doesn't work and can you explain me that cache I need to use when saving something how to set cache(activate it)?

EDIT: i asked this about cache because you we're right my log says "cache_insert_id() - no active cache"
Reply
#7

Ah, ok. When you are using unthreaded queries, the server has to wait until you get result. When I'm saying server, that means all commands, and everything will be unresponsive for all players. That's why we are using threaded queries. It creates separate thread in your server's CPU, and calls back to your script when the result is ready (at least that's how I understand it). Lag eliminated, but requires you to provide a callback - function which will be called after retrieving results. It has to be a public function, like with timers. So, your code has to look like:

pawn Код:
stock GetName(playerid)
{
    new AccName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, AccName, sizeof(AccName));
    return pName;
}

public OnPlayerDisconnect(playerid, reason)
{
    mysql_format(sqldb, query, sizeof(query), "INSERT INTO accounts (accname) VALUES ('%e')", GetName(playerid));
    mysql_tquery(sqldb, query, "InsertCallback", "d", playerid);
    return 1;
}

forward InsertCallback(playerid);
public InsertCallback(playerid)
{
    PlayerInfo[playerid][pSQLID] = cache_insert_id(sqldb);

    printf("Player %d was saved with dbID %d", playerid, PlayerInfo[playerid][pSQLID]);
    return 1;
}
I used %e and mysql_format - ****** sql injection to learn about dangers of using %s instead %e with strings.
Reply
#8

Thx, works properly. rep for you dude.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)