Passing query SELECT `test` FROM `table` WHERE `name` = 'e' LIMIT 0,1 | d ProcessQueryThread(OnAPublic) - Query was successful. (SELECT `test` FROM `table` WHERE `name` = 'e' LIMIT 0,1)
new query[64];
format(query, sizeof(query), "SELECT `test` FROM `table` WHERE `name` = '%e' LIMIT 0,1", GetName(playerid));
mysql_function_query(Handler, query, true, "OnAPublic", "d", playerid);
forward OnAPublic(playerid);
public OnAPublic(playerid)
{
// ......
return 1;
}
GePlayerName(playerid)
{
new name[MAX_PLAYER_NAME]
GetPlayerName(playerid, name, sizeof(name));
return name;
}
stock CheckUser(playerid, name[MAX_PLAYER_NAME])
{
new query[124];
format(query, sizeof(query), "SELECT `name` FROM `table` WHERE `name` = '%s'", name);
mysql_function_query(1, query, true, "OnUserCheck", "d", playerid);
}
forward OnUserCheck(playerid); // Andre
public OnUserCheck(playerid) // Andre
{
if(playerid != INVALID_PLAYER_ID)
{
new rows, fields;
cache_get_data(rows, fields);
if(rows == 1)
{
// Account already exists!
}
else
{
// No account!
}
}
return 1;
}
new DBResult:dbresult, string[128];
format(string, sizeof(string), "SELECT NAME FROM `USERS` WHERE `NAME`='%s'", DB_Escape(RPN(playerid)));
dbresult = db_query(UserDatabase, string);
if(db_num_rows(dbresult) > 0)
{
// something
}
else
{
// something
}
db_free_result(dbresult);
That's not really help me though... R7 has this build in (clears the chace) unlike the older versions..
I'm not sure how to create this function since in order to clear stuff you have to return 1 at the end.. All I want is a function that returns either true or false whenever checking if a string (user) exists (without breaking anything). |
#include <a_samp>
#include <a_mysql>
new
SQLConnection ; // variable.
public OnGameModeInit()
{
return SQLConnection = mysql_connect( "Host", "Username", "Database", "Password" );
}
public OnPlayerConnect( playerid )
{
return CheckUser( playerid );
}
stock CheckUser( playerid )
{
new
query [ 128 ], name[ MAX_PLAYER_NAME ];
GetPlayerName( playerid, name, sizeof( name ) );
format( query, sizeof( query ), "SELECT `name` FROM `table` WHERE `name` = '%s'", name );
return mysql_function_query( SQLConnection, query, true, "OnUserCheck", "d", playerid );
}
forward OnUserCheck( playerid ); // Andre
public OnUserCheck( playerid ) // Andre
{
if( playerid != INVALID_PLAYER_ID )
{
new
rows, fields ;
cache_get_data( rows, fields, SQLConnection );
if( rows == 1 )
{
// Account already exists!
}
else
{
// No account!
}
}
return true;
}
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase Header size: 300 bytes Code size: 692 bytes Data size: 376 bytes Stack/heap size: 16384 bytes; estimated max. usage=528 cells (2112 bytes) Total requirements: 17752 bytes [Finished in 0.1s]
At the first look of your cool it looks confusing because, you can't the name when player connects to the server, your code should look something like this but I am not sure if this is what you want.
Pawn Code pawn Код:
Код:
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase Header size: 300 bytes Code size: 692 bytes Data size: 376 bytes Stack/heap size: 16384 bytes; estimated max. usage=528 cells (2112 bytes) Total requirements: 17752 bytes [Finished in 0.1s] |
public OnUserCheck( playerid ) // Andre
{
if( playerid != INVALID_PLAYER_ID )
{
new
rows, fields ;
cache_get_data( rows, fields, SQLConnection );
if( rows == 1 )
{
// Account already exists!
return 1;
}
else
{
// No account!
return 0;
}
}
return true;
}