Latest MySQL version problem -
Kraeror - 14.01.2018
Hello guys! As I said in the title I'm using the latest MySQL version! When I'm trying to check if player's name exists it always create another account with the same name. Here is my code:
PHP код:
new string[256];
format(string, 128, "SELECT * FROM `accounts` WHERE Username = '%e'", PlayerName(playerid));
mysql_tquery(zMySQL, string);
if(cache_num_rows())
{
//My Register Code
}
else
{
//My Login Code
}
Re: Latest MySQL version problem -
m4karow - 14.01.2018
Код:
new string[256];
format(string, 128, "SELECT * FROM `accounts` WHERE Username = '%e'", PlayerName(playerid));
mysql_tquery(zMySQL, string, "OnAccountCheck", "d", "playerid);
Код:
public OnAccountCheck(playerid)
{
if(cache_num_rows())
{
//My Register Code
}
else
{
//My Login Code
}
}
Re: Latest MySQL version problem -
Kraeror - 14.01.2018
Thank you m4karow, +1 REP
Re: Latest MySQL version problem -
Dayrion - 14.01.2018
Read this :
http://forum.sa-mp.com/showpost.php?...79&postcount=1
Plus: when you use "format", use sizeof(..) instead of putting a numeric value. It's better if you need to change the string's size at the declaration.
Re: Latest MySQL version problem -
Mikro - 14.01.2018
Note that cache_num_rows() returns the amount of rows. Which means it will be 0 aka false when there is no account yet. Your if blocks should be turned around:
Код:
if(cache_num_rows())
{
// My Login Code
}
else
{
// My Register Code
}
Re: Latest MySQL version problem -
denNorske - 14.01.2018
There is one thing you left out, and it was this:
the function "format" doesn't support escaping, so instead you should use the provided function "mysql_format" instead. Documentation:
https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_format
Therefore, your query never finds any other accounts, because the server sends the format with the %e, and not the name you want.
Re: Latest MySQL version problem -
Kaperstone - 14.01.2018
new string[
256];
format(string,
128,
String sizes are different and I don't think you need that long of a string, you just waste memory.
44 char long is the query without the name, add to it 24 for the username, +1 for terminal = 69 long string.
new string[69];
It'd mean that you'd have 187 unused/empty cells at all times.