MySQL Plugin
Najbolji i najpopularniji MySQL plugin za SA:MP!
10/12/2013:
Projekt prebacen sa googlecode na github
Ovaj plugin vam omogucava da koristite MySQL u PAWNu. Projekt trenutno razvijaju Pain123/maddinat0r; naci ces
sve starije verzije ukljucujuci
source code i
primjere skripti, od R5 do R7 na
kraju ovog posta, a zadnju verziju mozete pronaci na
GitHub (https://github.com/pBlueG/SA-MP-MySQL/releases)
Project Home (https://github.com/pBlueG)
Zadnje izmjene (https://github.com/pBlueG/SA-MP-MySQL/commits/master)
Source Code (https://github.com/pBlueG/SA-MP-MySQL/tree/master/src)
Download (https://github.com/pBlueG/SA-MP-MySQL/releases)
Wiki (Version >= R33) (http://wiki.sa-mp.com/wiki/MySQL/R33)
Kako instalirati:Kopirajte mysql.dll (windows) ili mysql.so (linux) u vas folder 'plugins/'. Ako koristite windows morate preuzeti mysql library (libmysql.dll, pogledaj download stranicu) i kopirati ga u glavni folder vaseg servera. Server conifg (server.cfg) mora biti izmjenjen takodje.
Windows: plugins mysql
Linux: plugins mysql.so
PAWN Scripting R5-R7: (a_mysql.inc) - Native functions: (Svi parametri u zagradama su opcioni.)
- * = R5, R6 (Podrzava threaded and non-threaded skripte)
- * = R7 (Podrzava samo threaded scripts)
- Caching tutorial - Click! (http://forum.sa-mp.com/showthread.php?t=337810) mysql_affected_rows (http://wiki.sa-mp.com/wiki/MySQL#mysql_affected_rows)( [connectionHandle = 1] ) * *
mysql_close (http://wiki.sa-mp.com/wiki/MySQL#mysql_close)( [connectionHandle = 1] ) * *
- Make sure you call this on OnGameModeExit()/OnFilterscriptExit()
mysql_connect (http://wiki.sa-mp.com/wiki/MySQL#mysql_connect)( const host[], const user[], const database[], const password[] ) *
mysql_connect (http://wiki.sa-mp.com/wiki/MySQL#mysql_connect)( const host[], const user[], const database[], const password[] [, port = 3306] ) *
- Returns a connection handle you can use for multiple connections
mysql_debug (http://wiki.sa-mp.com/wiki/MySQL#mysql_debug)( enable = 1 ) * *
- Enables the debug modus and creates a log file named mysql.log
mysql_errno (http://wiki.sa-mp.com/wiki/MySQL#mysql_errno)( [connectionHandle = 1] ) * *
mysql_fetch_int (http://wiki.sa-mp.com/wiki/MySQL#mysql_fetch_int)( [connectionHandle = 1] ) *
mysql_fetch_field_row (http://wiki.sa-mp.com/wiki/MySQL#mysql_fetch_field_row)( string[], const fieldname[] [,connectionHandle = 1] ) * *
mysql_fetch_float (http://wiki.sa-mp.com/wiki/MySQL#mysql_fetch_float)( &Float:result [,connectionHandle = 1] ) *
mysql_fetch_row_format (http://wiki.sa-mp.com/wiki/MySQL#mysql_fetch_row_format)( string[], const delimiter[] = "|" [,connectionHandle = 1] ) * *
mysql_field_count (http://wiki.sa-mp.com/wiki/MySQL#mysql_field_count)( [connectionHandle = 1] ) * *
mysql_format (http://wiki.sa-mp.com/wiki/MySQL#mysql_format)( connectionHandle, output[], format[], {Float,_}:... ) * (works on
R6-2 aswell)
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 (http://wiki.sa-mp.com/wiki/MySQL#mysql_free_result)( [connectionHandle = 1] ) * *
mysql_get_charset (http://wiki.sa-mp.com/wiki/MySQL#mysql_get_charset)( destination[] [,connectionHandle = 1] ) * *
mysql_insert_id (http://wiki.sa-mp.com/wiki/MySQL#mysql_insert_id)( [connectionHandle = 1] ) * *
mysql_num_rows (http://wiki.sa-mp.com/wiki/MySQL#mysql_num_rows)( [connectionHandle = 1] ) * *
mysql_num_fields (http://wiki.sa-mp.com/wiki/MySQL#mysql_num_fields)( [connectionHandle = 1] ) * *
mysql_ping (http://wiki.sa-mp.com/wiki/MySQL#mysql_ping)( [connectionHandle = 1] ) * *
- Returns true (1) if the connection is alive, else (-1)
mysql_query (http://wiki.sa-mp.com/wiki/MySQL#mysql_query)( query[] [,resultid = (-1), extraid = (-1), connectionHandle = 1] ) *
- Setting result id to something else than (-1), triggers the OnQueryFinish callback
mysql_query_callback (http://wiki.sa-mp.com/wiki/MySQL#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 (http://wiki.sa-mp.com/wiki/MySQL#mysql_real_escape_string)( iconst source[], destination[] [,connectionHandle = 1] ) * *
mysql_reconnect (http://wiki.sa-mp.com/wiki/MySQL#mysql_reconnect)( [connectionHandle = 1] ) * *
mysql_reload (http://wiki.sa-mp.com/wiki/MySQL#mysql_reload)( [connectionHandle = 1] ) **
mysql_retrieve_row (http://wiki.sa-mp.com/wiki/MySQL#mysql_retrieve_row)( [connectionHandle = 1] ) **
- Returns true (1) incase there are still rows to retrieve, else false (0)
mysql_set_charset (http://wiki.sa-mp.com/wiki/MySQL#mysql_set_charset)( charset[] [,connectionHandle = 1] ) **
mysql_stat (http://wiki.sa-mp.com/wiki/MySQL#mysql_stat)( const destination[] [,connectionHandle = 1] ) **
mysql_store_result (http://wiki.sa-mp.com/wiki/MySQL#mysql_store_result)( [connectionHandle = 1] ) **
mysql_warning_count (http://wiki.sa-mp.com/wiki/MySQL#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,_}:... ) *
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 (http://wiki.sa-mp.com/wiki/MySQL#OnQueryFinish)( query[], resultid, extraid, connectionHandle ) * -
Sample usage (updated) (http://forum.sa-mp.com/showthread.php?p=323895#post323895)
OnQueryError (http://wiki.sa-mp.com/wiki/MySQL#OnQueryError)( errorid, error[], resultid, extraid, callback[], query[], connectionHandle ) *
OnQueryError ( errorid, error[], callback[], query[], connectionHandle ) *
Compiling Notes: -
Windows: Otvorite projekt sa Microsoft Visual C++ i kliknite build dugme. (MySQL Visual Studio/C++ je potrebno)
-
Linux: Install gcc, gpp & mysql-client i upisite "make" u folderu source fajlova.
Downloads: (za nove updatove, korisitite github stranicu na vrhu posta!) NOTE: NEMOJ KORISTITI VERZIJU R7 I VECU AKO NE ZNAS STA ZNACI THREADING I KAKO SE KORISTI. MOZES JEDINO OSTETITI SVOJ SERVER AKO GA NE KORISTIS PRAVILNO. -
Windows: (zahtjeva .NET Framework) R7: Server plugin (VS9) (http://files.g-stylezzz.com/mysql/rel/R7/windows/plugin-R7-win32_vs9.rar)
R6: Server plugin (VS9) (http://files.g-stylezzz.com/mysql/rel/R6/windows/plugin-R6-win32_vs9.rar)
R5: Server plugin (VS9) (http://files.g-stylezzz.com/mysql/rel/R5/windows/plugin-R5-win32_vs9.rar)
libmysql.dll (http://files.g-stylezzz.com/libmySQL.dll)
-
Linux: (x86 (32-bit) version is cross compatible) R7: Ubuntu (http://files.g-stylezzz.com/mysql/rel/R7/ubuntu/mysql.so),
x86 (compiled on Ubuntu) (http://files.g-stylezzz.com/mysql/rel/R7/x86/mysql.so)
R6: CentOS (http://files.g-stylezzz.com/mysql/rel/R6/centos/mysql.so),
Debian 5 (http://files.g-stylezzz.com/mysql/rel/R6/debian5/mysql.so),
x86 (compiled on CentOS) (http://files.g-stylezzz.com/mysql/rel/R6/x86/mysql_centos.so),
x86 (compiled on Debian5) (http://files.g-stylezzz.com/mysql/rel/R6/x86/mysql_debian.so)
R5: CentOS (http://files.g-stylezzz.com/mysql/rel/R5/centos/mysql.so),
Debian 5 (http://files.g-stylezzz.com/mysql/rel/R5/debian5/mysql.so),
x86 (http://files.g-stylezzz.com/mysql/rel/R5/x86/mysql.so)
libmysqlclient.so.15 (http://www.mow.vg/files/libmysqlclient.so.15) - Getting this error.. 'libmysqlclient.so.15: cannot open shared [..]' ? -
Read This (http://forum.sa-mp.com/showpost.php?p=521284&postcount=553)
-
Scripting: R7: a_mysql.inc (http://files.g-stylezzz.com/mysql/rel/R7/a_mysql.inc),
Sample Script (http://files.g-stylezzz.com/mysql/rel/R7/ip2country.rar) (shows how to use the cache_*() functions), Blank Gamemode (uses the cache method)
R5, R6: a_mysql.inc (http://files.g-stylezzz.com/mysql/rel/a_mysql.inc),
Sample Script (http://files.g-stylezzz.com/mysql/rel/user_script.pwn)
Archive: PHP Class (http://files.g-stylezzz.com/mysql/SQL_PHP.rar),
Modified sample script (by nemesis) (http://files.g-stylezzz.com/mysql/rel/user_script_nemesis.pwn) (only >= R5 compatible)
-
Source: (Cross-Compatible) R7: Source code (http://files.g-stylezzz.com/mysql/R7/plugin-R7-src_final.rar)
R6: Source code (http://files.g-stylezzz.com/mysql/rel/R6/plugin-R6-src_final.rar)
R5: Source code (http://files.g-stylezzz.com/mysql/rel/R5/plugin-R5-src_final.rar)
Zahvale: 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)
Pain123 (Developing the plugin as of R8)
Sergei (Testing/Suggestions/Wiki documentation)
xxmitsu (Testing/Compiling)