/easy-mysql

Simplifies the usage of MySQL, making it user friendly and similar to INI schemes.

Primary LanguageSourcePawnApache License 2.0Apache-2.0

#Easy-MySQL

Easy-MySQL is a plugin designed to simply the usage of MySQL queries, specially if you want to run long queries and you're not willing to create a lot of strings for it.

#Download

Go to the releases page and download the latest easy-mysql.inc file available.

#Installation

  • Place the easy-mysql.inc file you downloaded in your includes folder.
  • Include the easy-mysql in your PAWN script.
#include <easy-mysql> 

#Requirements:

In order to use this include, you require the MySQL Plugin by BlueG.

#Functions and their usage:

###SQL::Connect

#####Description: Connects your script to a MySQL database with given parameters. ####Parameters:

(const host[], const user[], const password[], const database[], bool:debugging = false, port = 3306, bool:autoreconnect = true, pool_size = 2);´

####Return values: Connection handle retrieved by mysql_connect.

#define mysql_host    "localhost" 
#define mysql_user    "root" 
#define mysql_db        "server" 
#define mysql_pass         "" 

public OnGameModeInit() 
{ 
	SQL::Connect(mysql_host, mysql_user, mysql_pass, mysql_db); 
	return 1;
}

###SQL::DeleteRow

#####Description: Deletes a row in the specified table. ####Parameters:

(const table[], const column[], columnID, connectionHandle = 1);
  • const table[] The target MySQL table.
  • const column[] The column in the MySQL table.
  • columnID The unique ID that identifies the target row you want to delete.
  • connectionHandle (optional)The handle returned by SQL::Connect or mysql_connect.

####Return values: Always returns 1.

//Delete an user from a table called 'players', supposing the column is called 'p_id' and the player's column ID is 5.
SQL::DeleteRow("players", "p_id", 5);

###SQL::DeleteRowEx

#####Description: Deletes a row in the specified table. ####Parameters:

(const table[], const column[], columnID[], connectionHandle = 1);
  • const table[] The target MySQL table.
  • const column[] The column in the MySQL table.
  • columnID[] The string that identifies the target row you want to delete(might be his name?).
  • connectionHandle (optional)The handle returned by SQL::Connect or mysql_connect.

####Return values: Always returns 1.

//Delete an user from a table called 'players', supposing the column is called 'p_name' and the player's name is TestName.
SQL::DeleteRowEx("players", "p_name", "TestName");

###SQL::GetIntEntry

#####Description: Gets an integer field in a defined row. ####Parameters:

(const table[], const field[], const column[], columnID, connectionHandle = 1);
  • const table[] The target MySQL table.
  • const field[] The field to retrieve the integer from.
  • const column[] The column that identifies the selected row.
  • columnID The ID in the column that identifies the selected row.
  • connectionHandle (optional)The handle returned by SQL::Connect or mysql_connect.

####Return values: The retrieved integer, 0 if no integer was found.

//Get an user's score from a table called 'players', supposing the score column is called 'p_score', the identifier column is called 'p_id' and the player's id is 4.
new player_score = SQL::GetIntEntry("players", "p_score", "p_id", 4);

###Float:SQL::GetFloatEntry

#####Description: Gets a float field in a defined row. ####Parameters:

(const table[], const field[], const column[], columnID, connectionHandle = 1);
  • const table[] The target MySQL table.
  • const field[] The field to retrieve the integer from.
  • const column[] The column that identifies the selected row.
  • columnID The ID in the column that identifies the selected row.
  • connectionHandle (optional)The handle returned by SQL::Connect or mysql_connect.

####Return values: The retrieved float, 0 if no float was found.

//Get an user's x_pos from a table called 'players', supposing the posx column is called 'p_X', the identifier column is called 'p_id' and the player's id is 4.
new Float:playerX = SQL::GetFloatEntry("players", "p_X", "p_id", 4);

###SQL::GetIntEntryEx

#####Description: Gets an integer field in a defined row. ####Parameters:

(const table[], const field[], const column[], columnID[], connectionHandle = 1);
  • const table[] The target MySQL table.
  • const field[] The field to retrieve the integer from.
  • const column[] The column that identifies the selected row.
  • columnID[] The string in the column that identifies the selected row(might be a player's name?).
  • connectionHandle (optional)The handle returned by SQL::Connect or mysql_connect.

####Return values: The retrieved integer, 0 if no integer was found.

//Get an user's score from a table called 'players', supposing the score column is called 'p_score', the identifier column is called 'p_name' and the player's name is TestName.
new player_score = SQL::GetIntEntryEx("players", "p_score", "p_name", "TestName");