SA-MP Forums Archive
Problem with get data MySQL - 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: Problem with get data MySQL (/showthread.php?tid=611095)



Problem with get data MySQL - MRM - 02.07.2016

Hello,
MySQL : R34

Log :
pawn Код:
[13:03:29] CheckAccount IS OK !
[13:03:29] OnAccountCheck IS OK !
[13:03:29] Get rows is OK! rows : - fields :
[13:03:29] pSQLid :  - pPass :

pawn Код:
stock CheckAccount(playerid)
{
    new query[82];
    printf("CheckAccount IS OK !");
    format(query, sizeof(query), "SELECT id, Password FROM `users` WHERE `Username` = '%s'", returnName(playerid));
    mysql_function_query(1, query, true, "OnAccountCheck", "d", playerid);
    return 1;
}
pawn Код:
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
    printf("OnAccountCheck IS OK !");
    if(playerid != INVALID_PLAYER_ID)
    {
   
        new rows, fields;
        cache_get_data(rows, fields);
        printf("Get rows is OK! rows : %s - fields : %s",rows,fields);
       
        if(rows)
        {
            Player[playerid][pSQLid] = cache_get_row_int(0, 0);
            cache_get_row(0, 3, Player[playerid][pPass], 1, 130);      
            printf("pSQLid : %s - pPass : %s",Player[playerid][pSQLid],Player[playerid][pPass]);
            ShowLoginScreen(playerid);
        }
        else
        {
            ShowRegisterScreen(playerid);
        }
    }
    return 1;
}



Re: Problem with get data MySQL - SyS - 02.07.2016

what is the problem?


Re: Problem with get data MySQL - MRM - 02.07.2016

rows, fields, pSQLid And pPass is empty.
pawn Код:
[13:03:29] Get rows is OK! rows : - fields :
[13:03:29] pSQLid :  - pPass :



Re: Problem with get data MySQL - MRM - 02.07.2016

mysql_log.txt
pawn Код:
[13:02:53] [DEBUG] CMySQLHandle::Create - creating new connection..
[13:02:53] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called
[13:02:53] [DEBUG] CMySQLHandle::Create - connection created with ID = 1
[13:02:53] [DEBUG] CMySQLConnection::Connect - connection was successful
[13:02:53] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[13:02:53] [DEBUG] CMySQLConnection::Connect - connection was successful
[13:02:53] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[13:03:29] [DEBUG] mysql_tquery - connection: 1, query: "SELECT id, Password FROM `users` WHERE `Username` = 'Miami'", callback: "OnAccountCheck", format: "d"
[13:03:29] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[13:03:29] [DEBUG] mysql_tquery - scheduling query "SELECT id, Password FROM `users` WHERE `Username` = 'Miami'"..
[13:03:29] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(d)] - starting query execution
[13:03:29] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(d)] - query was successful
[13:03:29] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[13:03:29] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(d)] - data being passed to ProcessCallbacks()
[13:03:29] [DEBUG] Calling callback "OnAccountCheck"..
[13:03:29] [DEBUG] cache_get_data - connection: 1
[13:03:29] [DEBUG] cache_get_row_int - row: 0, field_idx: 0, connection: 1
[13:03:29] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '0', data: "0"
[13:03:29] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[13:03:29] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called



Re: Problem with get data MySQL - xJayce - 02.07.2016

Update your MySQL plugin, also use %d or %i for integers in printf.


Re: Problem with get data MySQL - BroZeus - 02.07.2016

For sqlid use %d instead of %s in print line.
For pass, the cache_get_row line is wrong.
Here is the correct one :
Quote:

cache_get_row(0, 1, Player[playerid][pPass], 1, 130);

You had 3 in place of 1. It should be 1 as the index of password field is 1 according to your select line.


Re: Problem with get data MySQL - MRM - 02.07.2016

Fixed. Thanks @xJayce @BroZeus
pawn Код:
[13:36:17] Get rows is OK! rows : 1 - fields : 2
[13:36:17] pSQLid : 0 - pPass : 07A199D9A7E21A62464B36B87BB8F4A26DE7B61A4BC0FFDCB621E6913FB9F66BF6019461335A0E105FB5F8A217CD
MyDB : http://uploadpie.com/ekuDF
When the row is 1? ( cache_get_row(1 ,....) )
Thanks.


Re: Problem with get data MySQL - [cS]Owain - 02.07.2016

Quote:
Originally Posted by MRM
Посмотреть сообщение
Fixed. Thanks @xJayce @BroZeus
When the row is 1? ( cache_get_row(1 ,....) )
Thanks.
Row is 1 when there are more than one rows being selected. For example if you select all player data then number of rows in list is number of rows in the table.
Example :
PHP код:
mysql_function_query(1"SELECT id FROM `users`"true"Just_a_Example""");//see the query it will select id of all users
public Just_a_Example()
{
   new 
rows cache_get_row_count();//get num of rows in result
   
for(new 0;rowsi++)
   {
       new 
id cache_get_row_int(i0);//number of row changes here, see the 'i'
       
printf("User id :%d row: %d"idi); 
   }
   return 
1;




Re: Problem with get data MySQL - MRM - 02.07.2016

Thanks .