A little MySQL Help Here Please.
#1

Ok, so i converted, my script to mysql using BlueG's MySQL Plugin Version R5. Yeah, didnt really get the plugins R7+.

pawn Код:
stock MySQL_Login(playerid)
{
    new query[300], exec[256], string[256];
    format(query, sizeof(query), "SELECT * FROM `Accounts` WHERE `Nick` = '%s'", GetName(playerid));
    mysql_query(query);
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        if(mysql_retrieve_row())
        {
            mysql_fetch_field_row(result,"Admin");
            PlayerInfo[playerid][Admin] = strval(exec);
            mysql_fetch_field_row(result,"Score");
            PlayerInfo[playerid][Score] = strval(exec);
            mysql_fetch_field_row(result,"Money");
            PlayerInfo[playerid][Money] = strval(exec);
            mysql_fetch_field_row(result,"Kills");
            PlayerInfo[playerid][Kills] = strval(exec);
            mysql_fetch_field_row(result,"Deaths");
            PlayerInfo[playerid][Deaths] = strval(exec);
            mysql_fetch_field_row(result,"Muted");
            PlayerInfo[playerid][Muted] = strval(exec);
        }
    }
    mysql_free_result();
    GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
    SetPlayerScore(playerid, PlayerInfo[playerid][Score]);
    PlayerInfo[playerid][Login] = 1;
    if(PlayerInfo[playerid][Admin] >= 1)
    {
        format(string, sizeof(string), "[ACCOUNT] "cwhite"Successfully Logged in. Welcome Admin. Your Level is %d",PlayerInfo[playerid][Admin]);
        SCM(playerid, xgreen, string);
    }
    else
    {
        format(string, sizeof(string), "[ACCOUNT] "cwhite"Successfully Logged in.");
        SCM(playerid, xgreen, string);
    }
    return 1;
}
Here is my MySQL Login code. Everything In this stock except for the SCM without admin is not working.
What am I doing wrong? everything else including stats saving in the database is working but this login thingy isnt what am I doing wrong?
Reply
#2

Add this somewhere at the top of your script:

pawn Код:
#define SCM SendClientMessage
Or just replace SCM with SendClientMessage, because it's bad way to script.
Reply
#3

*_*
I said EVERYTHING is NOT working OTHER than the SCM(which means only SendClientMessage in that stock is working) and yeah I know its a bad scripting habit but.....
Reply
#4

Quote:
Originally Posted by iBeast
Посмотреть сообщение
*_*
I said EVERYTHING is NOT working OTHER than the SCM(which means only SendClientMessage in that stock is working) and yeah I know its a bad scripting habit but.....
My bad, I read that everything else works. I will find the problem out and edit my post.

Edit: sorry for my late response, but I couldn't really find a problem as I always use the latest plugins and I don't really remember how do the pre-R7 versions work.
Reply
#5

I do not suggest you using mysql_fetch_field_row for loading, I suggest you use sscanf it's much faster, if you use MySQL r7 below.
Reply
#6

can somebody guide me with the fetch field since I dont really understand sscanf that well.
Reply
#7

pawn Код:
stock MySQL_Login(playerid)
{
    new query[300], exec[20], string[256];
    format(query, sizeof(query), "SELECT * FROM `Accounts` WHERE `Nick` = '%s'", GetName(playerid));
    mysql_query(query);
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        if(mysql_retrieve_row())
        {
            mysql_fetch_field_row(exec,"Admin");
            PlayerInfo[playerid][Admin] = strval(exec);
            mysql_fetch_field_row(exec,"Score");
            PlayerInfo[playerid][Score] = strval(exec);
            mysql_fetch_field_row(exec,"Money");
            PlayerInfo[playerid][Money] = strval(exec);
            mysql_fetch_field_row(exec,"Kills");
            PlayerInfo[playerid][Kills] = strval(exec);
            mysql_fetch_field_row(exec,"Deaths");
            PlayerInfo[playerid][Deaths] = strval(exec);
            mysql_fetch_field_row(exec,"Muted");
            PlayerInfo[playerid][Muted] = strval(exec);
        }
    }
    mysql_free_result();
    GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
    SetPlayerScore(playerid, PlayerInfo[playerid][Score]);
    PlayerInfo[playerid][Login] = 1;
    if(PlayerInfo[playerid][Admin] >= 1)
    {
        format(string, sizeof(string), "[ACCOUNT] "cwhite"Successfully Logged in. Welcome Admin. Your Level is %d",PlayerInfo[playerid][Admin]);
        SCM(playerid, xgreen, string);
    }
    else
    {
        format(string, sizeof(string), "[ACCOUNT] "cwhite"Successfully Logged in.");
        SCM(playerid, xgreen, string);
    }
    return 1;
}
Reply
#8

Quote:
Originally Posted by iBeast
Посмотреть сообщение
can somebody guide me with the fetch field since I dont really understand sscanf that well.
This should work sscanf version.

pawn Код:
stock MySQL_Login(playerid)
{
    new query[300], string[256];

    format( query, sizeof( query ), "SELECT * FROM `Accounts` WHERE `Nick` = '%s'", GetName( playerid ) );
    mysql_query( query );

    mysql_store_result( );

    if( mysql_num_rows( ) )
    {
        if(mysql_fetch_row_format(query, "|"))
        {
            sscanf(query, "p<|>iiiiii", PlayerInfo[playerid][Admin], PlayerInfo[playerid][Score], PlayerInfo[playerid][Money], PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], PlayerInfo[playerid][Muted]);
        }
    }
    mysql_free_result( );

    GivePlayerMoney( playerid, PlayerInfo[playerid][Money] ), SetPlayerScore( playerid, PlayerInfo[playerid][Score] );

    PlayerInfo[ playerid ][ Login ] = 1;

    if(PlayerInfo[playerid][Admin] >= 1)
    {
        format(string, sizeof(string), "[ACCOUNT] "cwhite"Successfully Logged in. Welcome Admin. Your Level is %d",PlayerInfo[playerid][Admin]);
        SCM(playerid, xgreen, string);
    }
    else
    {
        format(string, sizeof(string), "[ACCOUNT] "cwhite"Successfully Logged in.");
        SCM(playerid, xgreen, string);
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
This should work sscanf version.

pawn Код:
stock MySQL_Login(playerid)
{
    new query[300], string[256];

    format( query, sizeof( query ), "SELECT * FROM `Accounts` WHERE `Nick` = '%s'", GetName( playerid ) );
    mysql_query( query );

    mysql_store_result( );

    if( mysql_num_rows( ) )
    {
        if(mysql_fetch_row_format(query, "|"))
        {
            sscanf(query, "p<|>iiiiii", PlayerInfo[playerid][Admin], PlayerInfo[playerid][Score], PlayerInfo[playerid][Money], PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], PlayerInfo[playerid][Muted]);
        }
    }
    mysql_free_result( );

    GivePlayerMoney( playerid, PlayerInfo[playerid][Money] ), SetPlayerScore( playerid, PlayerInfo[playerid][Score] );

    PlayerInfo[ playerid ][ Login ] = 1;

    if(PlayerInfo[playerid][Admin] >= 1)
    {
        format(string, sizeof(string), "[ACCOUNT] "cwhite"Successfully Logged in. Welcome Admin. Your Level is %d",PlayerInfo[playerid][Admin]);
        SCM(playerid, xgreen, string);
    }
    else
    {
        format(string, sizeof(string), "[ACCOUNT] "cwhite"Successfully Logged in.");
        SCM(playerid, xgreen, string);
    }
    return 1;
}
PDS2k12 thanks man now i have also learnt how to use Sscanf with MYSQL

+REP Your Yea

EDIT: Sorry man i cant give rep Error: You Must Spread Some Reputation around before giving it back to PDS2k12
Reply
#10

though I fixed it myself but thanks pds2k12 because I learned mysql with sscanf.
Danyal, the fix you gave was just a change in the "result" thingy which wasnt the real problem I had fixed it in my script.
I fixed it with using mysql_fetch_field_row.
Cant rep anyone of you due to too many reps given out in past 24 hours.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)