mysql num rows? - 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: mysql num rows? (
/showthread.php?tid=321801)
mysql num rows? -
PawnoQ - 28.02.2012
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);
}
Re: mysql num rows? -
TheArcher - 28.02.2012
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
Re: mysql num rows? -
PawnoQ - 28.02.2012
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
Re: mysql num rows? -
TheArcher - 28.02.2012
I guess it doesn't return any values untill the connection is stable.