MySQL Plugin R5

Started by -=[Vyorel]=-, Jun 15, 2011, 01:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jun 15, 2011, 01:23 AM Last Edit: Sep 05, 2013, 02:01 PM by Gireada
MySQL Plugin R5


Original post: AICI
17/07/2011:
- mysql_format() a fost adaugata)
09/07/2011:
- buguri legate de query rezolvate


Cum il instalezi:


  • Windows: Copiaza mysql.dll in folderul /plugins si libmysql.dll folderul serverului tau. Apoi adauga in server.cfg 'plugins mysql'
  • Linux: Copiaza mysql.so in folderul /plugins si adauga in server.cfg 'plugins mysql.so'
PAWN Scripting: (a_mysql.inc)


  • Functii Native: (Toti parametrii din parantezele patrate sunt optionalel)

    • mysql_affected_rows( [connectionHandle = 1] )
    • mysql_close( [connectionHandle = 1] )

      • Asigura-te ca "chemi" acesta in OnGameModeExit()/OnFilterscriptExit()
    • mysql_connect( const host[], const user[], const database[], const password[] )

      • Returns a connection handle you can use for multiple connections

//acest exemplu demonstreaza cum sa folosesti mai multe conexiuni
new SQLPtr[2]; //global var
...
Function()
{
   SQLPtr[0] = mysql_connect(...);
   SQLPtr[1] = mysql_connect(...);
   mysql_query("SELECT a FROM table WHERE foo = 'bar'",(-1),(-1),SQLPtr[0]); //select query in the first DB
   mysql_query("UPDATE b SET bar = 'foo'",(-1),(-1),SQLPtr[1]); //update query in the second DB
   mysql_close(SQLPtr[1]); //close the 2nd DB connection, the other connection still exists

    • mysql_debug( activat = 1 )

      • Activeaza-l si creaza un fisier log cu numele 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 = 1] )
      [pawn]Supoerta: (%2.f/%10.s nu sunt suportate)
      - %e (scapa de date direct,fara a fi nevoie de  mysql_escape_string() inainte,dar nu da si query!)
      - %s (string)
      - %d / %i (integer)
      - %f (float)

      new szDestination[100];
      mysql_format(connectionHandle, szDestination, "SELECT * FROM `%s` WHERE `bar` = '%e' AND `foobar` = '%f' LIMIT %d", "foobar", "escape'me\"please", 1.2345, 1337);
      //variabila 'szDestination' contine stringul fara caractere care ar purea face SQL INJECTION
      mysql_query(szDestination);[/pawn]
    • 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] )

      • Adauga return 1; daca conexiunea este activa, daca nu adauga return -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] )


  • 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 )

Compiling Notes:


  • Windows: Deschide fisierul de proiect cu Microsoft Visual C++ si click pe bunonul build. (MySQL Visual Studio/C++ este necesar)
  • Linux: Instaleaza gcc, gpp & mysql-client si scrie "make" in fisierele sursa.
Download:

Daca nu intelegi ceva, posteaza aici.

Stiu ca nu am tradus tot dar nu am avut timp. O sa-l traduc complet. ;)



Atentie:
Fiti foarte atenti la SQL Injection,sunt multi rau-voitori.
https://docs.google.com/Doc?docid=0AZNlBave77hiZGNjanptbV84Z25yaHJmMjk&pli=1#Allowed_Intermediary_Character_30801873723976314

Ce e intre ( si ) de la functii nu trebuie tradus neaparat, lasa asa.

Nice (: