20.12.2013, 15:41
(
Последний раз редактировалось Rock; 06.04.2014 в 18:55.
)
Part 4:
This part will contain the last functions of BUD which you will see below.
BUD::RunQuery - Run a Query by yourself.
Parameters:
query[ ] - Name of the Query you want to send to the database.
bool: store_results - Store the results?
Example use(count registered users):
ATTENTION: There is no need for db_free_result after using BUD::RunQuery, BUD will take care of that for you.
-----------------------------------------------------------------------------------
BUD::EscapeSqlString - Used to prevent sql injections.
To protect your query from SQL injections simply run BUD::EscapeSqlString with the string you will insert as an argument.
If you're doing this for something enclosed in ` quotes:
-----------------------------------------------------------------------------------
BUD::GetSortedData - Get the data sorted from a specified column.
Parameters:
results[ ][ ][ ] - Results, you need to define them(see below)
column - Sort the results from what column?
BUD::GetNamesForSortedData - Get names for sorted data.
Parameters:
results[ ][ ][ ] - The string where sorted that was stored
num_results - Variable in which GetSortedData stored the results.
names[ ][ ] - A new variable to store the extracted names.
Example use for both:
-----------------------------------------------------------------------------------
BUD::SetPassword - Change password for account
Parameters:
uid - Unique id of player
password - New password(It will be automatically hashed)
Example:
WARNING: Before you use this function add this somewhere in bud.inc
This part will contain the last functions of BUD which you will see below.
BUD::RunQuery - Run a Query by yourself.
Код:
BUD::RunQuery( query[ ], bool:store_results )
query[ ] - Name of the Query you want to send to the database.
bool: store_results - Store the results?
Example use(count registered users):
pawn Код:
new
iCount,
szBuffer[ 32 ],
DBResult: iResult = BUD::RunQuery( "SELECT COUNT(*) FROM `users`", true );
if ( iResult )
{
db_get_field( iResult, 0, szBuffer, 31 );
iCount = strval( szBuffer );
}
-----------------------------------------------------------------------------------
BUD::EscapeSqlString - Used to prevent sql injections.
To protect your query from SQL injections simply run BUD::EscapeSqlString with the string you will insert as an argument.
If you're doing this for something enclosed in ` quotes:
pawn Код:
BUD::EscapeSqlString( string, '`' );
BUD::GetSortedData - Get the data sorted from a specified column.
pawn Код:
BUD::GetSortedData( &results[ ][ ], column )
results[ ][ ][ ] - Results, you need to define them(see below)
column - Sort the results from what column?
BUD::GetNamesForSortedData - Get names for sorted data.
pawn Код:
BUD::GetNamesForSortedData( results[ ][ ], num_results, names[ ][ ] )
results[ ][ ][ ] - The string where sorted that was stored
num_results - Variable in which GetSortedData stored the results.
names[ ][ ] - A new variable to store the extracted names.
Example use for both:
pawn Код:
new
BUD::Results: iMaxResults< 10 >, // Here we define results, < 10 > means how many variables will be sorted
szaNames[ 10 ][ MAX_PLAYER_NAME +1 ], // Name for GetNamesForSortedData, see below
iResults = BUD::GetSortedData( iMaxResults, "kills" ); // Store the sorted results into a variable
BUD::GetNamesForSortedData( iMaxResults, iResults, szaNames ); // Get names for all sorted data
if( iResults == BUD::INVALID_RESULTS ) // If sort failed.
printf( "BUD::GetSortedData failed." );
else
{
for ( new i = 0; i < iResults; i++ ) // Loop through results
{
printf( "User: %s (%d)\t%d", szaNames[ i ], brTest[ i ][ 0 ], brTest[ i ][ 1 ] );
}
}
BUD::SetPassword - Change password for account
pawn Код:
BUD::SetPassword( uid, const password[ ] )
uid - Unique id of player
password - New password(It will be automatically hashed)
Example:
pawn Код:
new
iUID = BUD::GetNameUID( GetName( playerid ) );
BUD::SetPassword( iUID, "test123" )
pawn Код:
global bool:BUD::SetPassword(uid, const password[]) {
if (uid == BUD::INVALID_UID || !BUD::GetDB()) {
return false;
}
new query[256];
#if (BUD::USE_WHIRLPOOL)
BUD::WhirlpoolHash(query, _, password);
format(query, sizeof(query), "UPDATE `users` SET `passhash` = x'%s' WHERE `uid` = %d", query, uid);
#else
new passhash[65];
BUD::JSCHash(password, passhash);
format(query, sizeof(query), "UPDATE `users` SET `passhash` = '%s' WHERE `uid` = %d", passhash, uid);
#endif
new DBResult:dbrResult = db_query(g_dbKeptAlive, query);
if (dbrResult) {
db_free_result(dbrResult);
return true;
}
return false;
}