Mysql "SELECT *"
#1

I have only just started using Mysql in my code i have a small IsPlayerRegistered function and i use "SELECT *" just to see if any columns are returned (thanks ****** ). Is that much more inefficient than just selecting one column? I know i could use either, but i would still like to know which is best to use in this situation.

pawn Код:
stock IsPlayerRegistered(playerid)
{
    new
        query[DEFAULT_QUERY_SIZE], eName[MAX_PLAYER_NAME];
       
    mysql_real_escape_string(gPlayerData[playerid][e_zPlayerName], eName);
    format(query, sizeof(query), "SELECT * FROM `users` WHERE `username` = '%s'", gPlayerData[playerid][e_zPlayerName]);//should i select all or one row here?
    mysql_query(query);
    mysql_store_result();

    if(mysql_num_rows() != 0)
    {
        mysql_free_result();
        return 1;
    }
    else
    {
        mysql_free_result();
        return 0;
    }
}
Thanks for your time.
Reply
#2

I'd just select the row, but I'm no good at MySQL. I wouldn't post here anyways, but what's the 'eName' string meant for if you're not using it?
Reply
#3

I use it to escape the players name (sql inject)
pawn Код:
mysql_real_escape_string(gPlayerData[playerid][e_zPlayerName], eName);
EDIT: LMAO i just noticed it wasn't used in the query thanks for spotting that.
Reply
#4

Hm, I have seen ****** once use SELECT null, maybe try that.
Reply
#5

Hmm i'm not sure what you mean. Like this?
pawn Код:
format(query, sizeof(query), "SELECT null FROM...
If so ill give it a try because i could use a much smaller query size.
Reply
#6

Yeah
Reply
#7

Works like a charm nice1.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)