mysql num rows?
#1

in case the mysql database doesnt respond for a moment (or connection dead)
the rows returned would be equal to 0 right?
So that would cause a re-registration of an allready existing member right?
So i made a ping code to check if the connection is still alive before going on with login.
Would that be ok or is it kinda senseless?

pawn Code:
//OnPlayerConnect
if(!mysql_ping())//connection alive
{
    new pnameq[24],query[128];
    GetPlayerName(playerid,pnameq,24);
    format(query, sizeof(query), "SELECT name FROM `ACCOUNTS` WHERE name = '%s' LIMIT 1", pnameq);
    mysql_query(query);
    mysql_store_result();
    new rows = mysql_num_rows();
    if(!rows)
    {
        //Register script, would INSERT new accounts
    }
    else if(rows == 1)
    {
        //Login script, would continue the old account
    }
}
else//connection dead so reconnect to database
{
    print("Reconnecting to the MYSQL Database...");
    new MySQL:connection = mysql_init(LOG_ONLY_ERRORS, 1);
    mysql_connect(mysql_host, mysql_user, mysql_password,mysql_database,connection,1);
}
Reply
#2

pawn Code:
//OnPlayerConnect
if(mysql_ping()!=0)//connection alive
{
    new pnameq[24],query[128];
    GetPlayerName(playerid,pnameq,24);
    format(query, sizeof(query), "SELECT name FROM `ACCOUNTS` WHERE name = '%s' LIMIT 1", pnameq);
    mysql_query(query);
    mysql_store_result();
    new rows = mysql_num_rows();
    if(rows<0)
    {
        //Register script, would INSERT new accounts
    }
    else if(rows => 1)
    {
        //Login script, would continue the old account
    }
}
else//connection dead so reconnect to database
{
    print("Reconnecting to the MYSQL Database...");
    new MySQL:connection = mysql_init(LOG_ONLY_ERRORS, 1);
    mysql_connect(mysql_host, mysql_user, mysql_password,mysql_database,connection,1);
}
try it
Reply
#3

thx.
But sorry, i think i didnt ask the right question
I wanna know if the script would return num_rows equal to 0 when the database is e.g. too busy to respond atm.
Or would the script be delayed untill the database responds?
I just wanna prevent re-registration so im asking if this code would make sense
Reply
#4

I guess it doesn't return any values untill the connection is stable.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)