jsql.inc is an additional include for BlueG's mysql plugin and will not work with any other.
The purpose of this include is to simplify mysql. The design of this include's functions is similiar to design of functions of many well known file systems, which makes it easier to get used to it and/or move to mysql from file systems.
The basic knowledge of mysql is recommended, even though not much is required.
Functions:
Code:
jsql_Connect(mysql_host[], mysql_user[], mysql_database[], mysql_password[]); jsql_Check(); jsql_Reconnect(); jsql_Disconnect(); jsql_TableExists(Name[]); jsql_TableCreate(Name[], Structure[]); jsql_TableRows(Name[]); jsql_TableRemove(Name[]); jsql_Exists(Table[], Identifier[], IdentifierValue[]); jsql_Add(Table[], Field[], Value[]); jsql_Remove(Table[], Identifier[], IdentifierValue[]); jsql_SetString(Table[], Identifier[], IdentifierValue[], Field[], Value[]); jsql_SetInt(Table[], Identifier[], IdentifierValue[], Field[], Value); jsql_SetFloat(Table[], Identifier[], IdentifierValue[], Field[], Float:Value); jsql_GetString(Table[], Identifier[], IdentifierValue[], Field[]); jsql_GetInt(Table[], Identifier[], IdentifierValue[], Field[]); jsql_GetFloat(Table[], Identifier[], IdentifierValue[], Field[]);
Usage:
In order to use any of this, you need to establish the connection to your database first.
Code:
#define MYSQL_HOST "localhost" #define MYSQL_USER "7echn0" #define MYSQL_DATABASE "mydatabase" #define MYSQL_PASSWORD "mypass" jsql_Connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD); // this should be under OnFilterScriptInit() or OnGameModeInit(). jsql_Check(); // returns either true or false, checks if connection to your database is valid jsql_Reconnect(); // reconnects to your database jsql_Disconnect(); // closes down the connection
In order to create a new table you need to specify the name and the structure with the size.
Code:
jsql_TableCreate("Users", "Name VARCHAR(25), Password VARCHAR(25), Score INT(5), Money INT(10)");
Code:
jsql_TableExists("Users");
jsql_TableRemove("Users");
jsql_TableRows("Users"); // returns the amount of rows in a table
In order to add a new row to a table you need to specify fields and values.
Code:
new Playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, Playername, sizeof(Playername));
new fields[50];
new values[20];
format(fields, sizeof(fields), "`Name`, `Password`, `Score`, `Money`");
format(values, sizeof(values), "'%s', '%s', %i, %i", Playername, "thisismypass", 50, 20);
jsql_Add("Users", fields, values);
In order to identify the row you want to work with, you need to specify identifier and identifier value.
Identifier is basically a field of a row, like: 'Name', 'Password', 'Score' or 'Money' and identifier value is a value that is stored in that field, like: '7echn0', 'thisismypass', '50', '20'.
Code:
jsql_Exists("Users", "Name", "7echn0");
jsql_Remove("Users", "Name", "7echn0");
Code:
jsql_SetString("Users", "Name", "7echn0", "Password", "thisismypass");
jsql_SetInt("Users", "Name", "7echn0", "Score", 50);
jsql_SetFloat("Users", "Name", "7echn0", "Health", 50.0);
Code:
jsql_GetString("Users", "Name", "7echn0", "Password");
jsql_GetInt("Users", "Name", "7echn0", "Score");
jsql_GetFloat("Users", "Name", "7echn0", "Health");
Download:
This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at http://ift.tt/jcXqJW.
Recommended article from FiveFilters.org: Most Labour MPs in the UK Are Revolting.
[Include] jsql.inc
Aucun commentaire:
Enregistrer un commentaire