[REL] MySQL Plugin (R7 released)
Za sve one koji pokrecu mod sa MySQL bazom ovo je najnoviji plugin
Citat
MySQL Plugin by BlueGKod: [Odaberi]02/03/2012:
- R7 has been completely released (there will be more documentation on the wiki soon)
25/02/2012:
- fixed a bug which has been reported by Deagle[WS]
- added a sample script and a windows dll
06/02/2012:
Due to the fact that I don't have much time at the moment, I've decided to release just the source
code for now. It's basically for users who want to improve their scripts. I will add more
information (such as plugins, documentation, sample scripts) at a later date.
Please note; R7 works only for [B][U]threaded[/U][/B] scripts!
17/07/2011:
- mysql_format() function has been added (see below for usage/syntax)
09/07/2011: (important to people who thread queries)
- added mutexes to provide thread safety (this should avoid random crashes)
- some code improvements & bug fixes
How to install:
Move mysql.dll (windows) or mysql.so (linux) to your 'plugins/' directory. On windows you'll have to download the mysql library (libmysql.dll, see downloads) and move it to your main server directory. The server configuration (server.cfg) has to be edited aswell.
- Windows
Kod: [Odaberi]plugins mysql
- Linux
Kod: [Odaberi]plugins mysql.so
PAWN Scripting: (a_mysql.inc)
- Native functions: (All parameters in squared brackets are optional)
- * = R5, R6 (supports threaded and non-threaded scripts)
- * = R7 (supports only threaded scripts)
- Caching guide - Click!
- mysql_affected_rows( [connectionHandle = 1] ) **
- mysql_close( [connectionHandle = 1] ) **
- Make sure you call this on OnGameModeExit()/OnFilterscriptExit()
- mysql_connect( const host[], const user[], const database[], const password[] ) *
- mysql_connect( const host[], const user[], const database[], const password[] [, port = 3306] ) *
- Returns a connection handle you can use for multiple connections
- mysql_debug( enable = 1 ) **
- Enables the debug modus and creates a log file named mysql.log
- mysql_errno( [connectionHandle = 1] ) **
- mysql_fetch_int( [connectionHandle = 1] ) *
- mysql_fetch_field_row( string[], const fieldname[] [,connectionHandle = 1] ) **
- mysql_fetch_float( &Float:result [,connectionHandle = 1] ) *
- mysql_fetch_row_format( string[], const delimiter[] = "|" [,connectionHandle = 1] ) **
- mysql_field_count( [connectionHandle = 1] ) **
- mysql_format( connectionHandle, output[], format[], {Float,_}:... ) * (works on R6-2 aswell)
Pawn: [Odaberi]Supported formats: (including precisions)
- %e (escapes a string at once, no mysql_real_escape_string() needed)
- %s (string)
- %d / %i (integer)
- %f (float)
- %x (hex)
- %b (binary)
new szDestination[100];
mysql_format(connectionHandle, szDestination, "SELECT * FROM `%s` WHERE `bar` = '%e' AND `foobar` = '%.2f' LIMIT %d", "foobar", "escape'me\"please", 1.2345, 1337);// the variable 'szDestination' contains now the formatted query (including the escaped string)mysql_query(szDestination);- mysql_free_result( [connectionHandle = 1] ) **
- mysql_get_charset( destination[] [,connectionHandle = 1] ) **
- mysql_insert_id( [connectionHandle = 1] ) **
- mysql_num_rows( [connectionHandle = 1] ) **
- mysql_num_fields( [connectionHandle = 1] ) **
- mysql_ping( [connectionHandle = 1] ) **
- Returns true (1) if the connection is alive, else (-1)
- mysql_query( query[] [,resultid = (-1), extraid = (-1), connectionHandle = 1] ) *
- Setting result id to something else than (-1), triggers the OnQueryFinish callback
- mysql_query_callback( index, query[], callback[] [, extraid = (-1), connectionHandle = 1] ) **
- Allows you to create custom callbacks for better structured coding (See sample_script.pwn below)
- mysql_real_escape_string( const source[], destination[] [,connectionHandle = 1] ) **
- mysql_reconnect( [connectionHandle = 1] ) **
- mysql_reload( [connectionHandle = 1] ) **
- mysql_retrieve_row( [connectionHandle = 1] ) **
- Returns true (1) incase there are still rows to retrieve, else false (0)
- mysql_set_charset( charset[] [,connectionHandle = 1] ) **
- mysql_stat( const destination[] [,connectionHandle = 1] ) **
- mysql_store_result( [connectionHandle = 1] ) **
- mysql_warning_count( [connectionHandle = 1] ) **
- cache_get_row( row, idx, dest[] [, connectionHandle = 1] ) *
- cache_get_field( field_index, dest[] [, connectionHandle = 1] ) *
- cache_get_data( &num_rows, &num_fields [, connectionHandle = 1] ) *
- cache_get_field_content( row, const field_name[], dest[] [, connectionHandle = 1] ) *
- enable_mutex( bool:enable ) *
- Disable mutexes incase you experience random crashes. (seems to happen on some linux distros only)
- mysql_function_query( connectionHandle, query[], bool:cache, callback[], format[], {Float,_}:... ) *
Pawn: [Odaberi]mysql_function_query(connectionHandle, "UPDATE `foo` SET `bar` = 1", false, "CustomResponse", "dsf", 1337, "string", 1.5634);
public CustomResponse(integer, string[], Float:float)
{
printf("Query successful executed. Data: %d | %s | %f", integer, string, float);
return 1;
}
- Pawn Callback:
- OnQueryFinish( query[], resultid, extraid, connectionHandle ) * - Sample usage (updated)
- This is just called if you used the 'resultid' parameter in the query function
- OnQueryError( errorid, error[], resultid, extraid, callback[], query[], connectionHandle ) *
- OnQueryError( errorid, error[], callback[], query[], connectionHandle ) *
Compiling Notes:Downloads:
- Windows: Open the project file with Microsoft Visual C++ and click the build button. (MySQL Visual Studio/C++ is required of course)
- Linux: Install gcc, gpp & mysql-client and type "make" in the source files folder.
Thanks to:
- Windows: (requires .NET Framework)
- Linux: (x86 (32-bit) version is cross compatible)
- R7: Ubuntu, x86 (compiled on Ubuntu)
- R6: CentOS, Debian 5, x86 (compiled on CentOS), x86 (compiled on Debian5)
- R5: CentOS, Debian 5, x86
- libmysqlclient.so.15 - Getting this error.. 'libmysqlclient.so.15: cannot open shared [..]' ? - Read this
- Scripting:
- R7: a_mysql.inc, Sample Script (shows how to use the cache_*() functions)
- R5, R6: a_mysql.inc, Sample PAWN script
- Archive: PHP class, Modified sample script (by nemesis) (only >= R5 compatible)
- Source: (Cross-Compatible)
- R7: Source code
- R6: Source code
- R5: Source code
- Chaprnks, Gehaktbal, JaTochNietDan, LS:RP Tester team, Webflori (Testing)
- AndreT (Testing/Cache Tutorial)
- JernejL (Testing/Suggestions)
- krisk (Testing/Suggestions)
- Kye (Coding support)
- Mow (Compiling/Testing/Hosting)
- nemesis (Testing)
- Sergei (Testing/Suggestions/Wiki documentation)
- xxmitsu (Testing/Compiling)
If you have any questions, post them here!
Primjedbe
Objavi komentar
Molimo bez vrijeđanja, nacionalizma ili slično,također, taj će biti sankcionisan!