Salut sunt RoW si astazi va prezint sistemul de salvare MySQL. Deci hai sa incepem xD. Avantaje: 1. Viteza 2. Capacitatea mare de date pe care o poate stoca. 3. In gamemode nu ocupa chiar atat de mult. Dezavantaje: 1. Greu de folosit ( Pentru incepatori ) 2. Greselile nu le semnaleaza pawno( Greselile de CLAUZE ) Sintaxe MySQL( r33 ) 1. mysql_connect - Face conexiunea cu database Handle = mysql_connect( MySQL_Host , MySQL_User , MySQL_Database , MySQL_Password ); La mysql_connect folositi o variabila globala ! Se folose?te doar la OnGameModeInit ( Doar acolo facem conexiunea ). 2. mysql_close - Inchide conexiunea cu database mysql_close( Handle ); mysql_close inchide conexiunea cu database ( De aceea folosim o variabila globala ). Se folose?te doar la OnGameModeExit ( Doar acolo inchidem conexiunea ). 3. mysql_tquery - Trimite un query( comanda ) catre database mysql_tquery( ID-ul conExiuni , stringul , numele thread-ului , parametri , definitie parametri ); Ex: mysql_tquery( Handle , "SELECT * FROM `accounts` WHERE `UserName` = '[.]..RoW..[.]' LIMIT 1;" , "LoadAccount" , "d" , playerid ); Se folose?te in orice callback. 4. cache_get_field_content_int - Extrage din database un integer cache_get_field_content_int( Rândul , Stringul , ID-ul de conExiune ); Ex: PlayerInfo[ playerid ][ pLevel ] = cache_get_field_content_int( 0 , "PlayerLevel" , Handle ); Se folose?te in interiorul stock-urilor/callback-urilor! 5. cache_get_field_content_float - Extrage din database un float cache_get_field_content_float( Rândul , Stringul , ID-ul de conExiune ); Ex: PlayerInfo[ playerid ][ pHealth ] = cache_get_field_content_float( 0 , "PlayerHealth" , Handle ); Se folose?te in interiorul stock-urilor/callback-urilor! 6. cache_get_field_content - Extrage din database un string cache_get_field_content( Rândul , Stringul , variabila de stocare , ID-ul de conExiune , Numarul de caractere ); cache_get_field_content( 0 , "PlayerMoto" , PlayerInfo[ playerid ][ pMoto ] , Handle , 24 ); Se folose?te in interiorul stock-urilor/callback-urilor! 7. mysql_real_escape_string(tExt,escape); mysql_real_escape_string( TExtul neprotejat , TExtul protejat ); Ex:
new
BadString[ 128 ] ,
GoodString[ 128 ] ;
format( BadString , 128 , "DELETE FORM `accounts` WHERE `UserName` = '%d' LIMIT 1;" , pName );
mysql_real_escape_string( BadString , GoodString , Handle );
mysql_tquery( Handle , GoodString , "LoadAccount" , "d" , playerid );
Se folose?te in interiorul stock-urilor/callback-urilor!
Cele mai cunoscute clauze:
INSERT INTO - Insereaz? în database.
new
pName[ 24 ] ,
test[ 256 ] ;
GetPlayerName( playerid , pName , 24 );
format( test , 256 , "INSERT INTO `accounts` ( UserName , LEvel ) VALUES ( '%s' '%d')" , pName );
mysql_tquery( Handle , test , "" , "" );
SELECT - Selecteaz? din database.
new
pName[ 24 ] ,
test[ 256 ] ;
GetPlayerName( playerid , pName , 24 );
format( test , 256 , "SELECT * FROM `accounts` WHERE `UserName` = '%s' LIMIT 1;" , pName );
mysql_tquery( Handle , test , "" , "" );
UPDATE - Updateaz? coloane din database.
new
pName[ 24 ] ,
test[ 256 ] ;
GetPlayerName( playerid , pName , 24 );
format( test , 256 , "UPDATE `accounts` SET `pLEvel` = '7' WHERE `UserName` = '%s' LIMIT 1;" , pName );
mysql_tquery( Handle , test , "" , "" );
DELETE - ?terge coloane din database.
new
pName[ 24 ] ,
test[ 256 ] ;
GetPlayerName( playerid , pName , 24 );
format( test , 256 , "DELETE FROM `accounts` WHERE `UserName` = '%s' LIMIT 1;" , pName );
mysql_tquery( Handle , test , "" , "" );
LIMIT - Limiteaz? Intr?rile/?tergerile/Updatarile
new
pName[ 24 ] ,
test[ 256 ] ;
GetPlayerName( playerid , pName , 24 );
format( test , 256 , "UPDATE `accounts` SET `pLEvel` = '7' WHERE `UserName` = '%s' LIMIT 1;" , pName );
mysql_tquery( Handle , test , "" , "" );
Oserva?ii: 1. Pentru a folosi MySQL trebuie s? ave?i instalat Wamp/Xampp 2. Pentru a perveni query-urile r?u inten?ionate( AKA SQL_Injection ) folositi mysql_real_escape_string Download: Google Project Page Acesta a fost tutorialul am încercat s? îl fac cât mai complex posibil !