[Include] C-MYSQL (Remade) - Increased Speed & More Simple
#1

C-MySQL
Information

Hi, I recently released a include called C-MySQL, the old include was:
  • Slow
  • Confusing
  • Little opportunity (Speed increasing wise)
Well, I decided to remake the script will some new functions and some functions removed. This time this can be useful.

Setup

There's a new way to set this up now. Instead of the useless parameters that made the include confusing, there are now defines that you can fill out. These defines are below:

pawn Code:
#define ACCOUNT_TABLE ""
#define USERNAME_FIELD ""
#define PASSWORD_FIELD ""
These defines should be filled in as below (This is an example):

pawn Code:
#define ACCOUNT_TABLE "Accounts"
#define USERNAME_FIELD "Username"
#define PASSWORD_FIELD "Password"
If you look inside the include you'll notice this:

pawn Code:
#if defined MYSQL_PLUGIN
    #include <a_mysql>
#else
    #include <mysql>
#endif
If you would like to use Strickenkid's MySQL plugin disable MYSQL_PLUGIN, like below:

pawn Code:
//#define MYSQL_PLUGIN // Defined = BlueG's plugin. | Undefined = Strickenkid's plugin.
These defines are found in the include ( C-MySQL.inc )

Functions (List)

Code:
native CMySQL_Create(Username[], Password[], bool:md5 = true, ThreadID = -1, extraID = -1);
native CMySQL_Delete(Username[], ThreadID = -1, extraID = -1);
native CMySQL_SetInt(Username[], Field[], Value, ThreadID = -1, extraID = -1);
native CMySQL_CustomDataSet(Username[], Custom[], ThreadID = -1, extraID = -1);
native CMySQL_Set(Username[], Field[], Value[], bool:md5 = false, ThreadID = -1, extraID = -1);
native CMySQL_SetFloat(Username[], Field[], Float:Value, ThreadID = -1, extraID = -1);
native CMySQL_SetBool(Username[], Field[], bool:Value, ThreadID = -1, extraID = -1);
native CMySQL_Load(Username[], ThreadID = -1, extraID = -1);
native CMySQL_Exists(Username[]);
native CMySQL_Int(Username[], Field[], ThreadID = -1, extraID = -1);
native CMySQL_Get(Username[], Field[], Storage[], ThreadID = -1, extraID = -1);
native Float:CMySQL_Float(Username[], Field[],ThreadID = -1, extraID = -1);
Functions (Explanation)

CMySQL_Create(Username[], Password[], bool:md5 = true, ThreadID = -1, extraID = -1)
Username - The account's username.
Password - The account's password.
bool:md5 - If true (default), then it md5 hashes the password, otherwise it doesn't.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_Create("Carlton", "MyPassword");
MySQL_Delete(Username[], ThreadID = -1, extraID = -1)
Username - The account's username.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_Delete("Carlton");
CMySQL_SetInt(Username[], Field[], Value, ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to set the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_SetInt("Carlton", "AdminLevel", 1337);
CMySQL_CustomDataSet(Username[], Custom[], ThreadID = -1, extraID = -1)
Username - The account's username.
Custom - The custom saving query.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_CustomDataSet("Carlton", "AdminLevel = 1337, Money = 10000, SkinID = 17");
CMySQL_Set(Username[], Field[], Value[], bool:md5 = false, ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to set the value to.
bool:md5 - If false (default), then it md5 hashes the value, otherwise it doesn't.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_Set("Carlton", "Password", "MyNewPassword", true);
CMySQL_SetFloat(Username[], Field[], Float:Value, ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to set the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_SetFloat("Carlton", "PosX", 1337.0);
CMySQL_SetBool(Username[], Field[], bool:Value, ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to set the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_SetBool("Carlton", "IsHungry", true);
CMySQL_Load(Username[], ThreadID = -1, extraID = -1);
Username - The account's username.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
#define MYSQL_LOAD_ACCOUNT (0)
CMySQL_Load("Carlton", MYSQL_LOAD_ACCOUNT, playerid);

public OnQueryFinish(...) {
     mysql_store_result();
     ....
}
CMySQL_Exists(Username[])
Username - The account's username.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the account exists.
Example:

pawn Code:
if(CMySQL_Exists("Carlton")) return print("Your account exists!");
CMySQL_Int(Username[], Field[], ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to get the value from.
ThreadID - For threading usages.
extraID - For threading usages.
returns the value of the field.
Example:

pawn Code:
new MyMoney = CMySQL_Int("Carlton", "Money");
CMySQL_Get(Username[], Field[], Storage[], ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to get the value from.
Storage - The string you'd like to store the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns nothing.
Example:

pawn Code:
new MyEmail[16];
CMySQL_Get("Carlton", "Email", MyEmail);
print(MyEmail);
Float:CMySQL_Float(Username[], Field[],ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to get the value from.
ThreadID - For threading usages.
extraID - For threading usages.
returns the value of the field.
Example:

pawn Code:
SetPlayerPos(playerid, CMySQL_Float("Carlton", "CrashPosX"), CMySQL_Float("Carlton", "CrashPosY"), CMySQL_Float("Carlton", "CrashPosZ"),
Example Script

pawn Code:
#include <a_samp>
#include <a_mysql>
#include <zcmd>
#include <sscanf2>

new MyMoney[MAX_PLAYERS], MyKills[MAX_PLAYERS];

stock GetUserName(playerid) {
      new name[24];
      GetPlayerName(playerid, name, 24); return name;
}

CMD:register(playerid, params[]) {
      if(CMySQL_Exists(GetUserName(playerid))
           return SendClientMessage(playerid, 0xFFFFFFA, "<> Your account exists already!");

      new password[32];
      if(sscanf(params, "s[32]", password))
           return SendClientMessage(playerid, 0xFFFFFFA, "<> /register <password>");
 
      if(strlen(password) > 32)
           return SendClientMessage(playerid, 0xFFFFFFA, "<> Your password must be 32 characters or less.");
 
      CMySQL_Create(GetUserName(playerid), password);
}

CMD:login(playerid, params[]) {
       if(!CMySQL_Exists(GetUserName(playerid))
           return SendClientMessage(playerid, 0xFFFFFFA, "<> Your account doesn't exist!");
 
      new password[32];
      if(sscanf(params, "s[32]", password))
           return SendClientMessage(playerid, 0xFFFFFFA, "<> /login <password>");
 
      if(strlen(password) > 32)
           return SendClientMessage(playerid, 0xFFFFFFA, "<> Your password must be 32 characters or less.");

      new Passwordz[32];
      CMySQL_Get(GetUserName(playerid), "Password", Passwordz, true);
      if(!strcmp(Passwordz, password, true)) {
           SendClientMessage(playerid, 0xFFFFFFA, "<> You're now logged.");
           CMySQL_Load(GetUserName(playerid), 1, playerid);
      }
}

stock GetMyAdminLevel(Username[]) {
     return CMySQL_Int(Username, "AdminLevel");
}

public OnPlayerDisconnect(playerid, reason) {
       new string[128];
       format(string, 128, "Money = %i, MyKills = %i", GetPlayerMoney(playerid), GetPlayerScore(playerid));
       CMySQL_CustomDataSet(GetUserName(playerid), string);
}

public OnQueryFinish( query[], resultid, extraid, connectionHandle ) {
      mysql_store_result();
      new Data[128];
      mysql_fetch_row_format(Data, "|");
      sscanf(Data, "p<|>ii", MyMoney[extraid], MyKills[extraid]);
      GivePlayerMoney(playerid, MyMoney[extraid]);
}
Requirements

You will need either BlueG's or Strickenkids plugin, these can be found below:

http://forum.sa-mp.com/forumdisplay.php?f=18

Thanks to

Strickenkid - Plugin.
BlueG - Plugin.

Download

Click below.
Reply


Messages In This Thread
C-MYSQL (Remade) - Increased Speed & More Simple - by Carlton - 10.08.2010, 08:50
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Grim_ - 10.08.2010, 08:54
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by DiddyBop - 10.08.2010, 08:58
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Carlton - 10.08.2010, 16:19
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Grim_ - 10.08.2010, 16:25
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Kar - 10.08.2010, 16:51
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Carlton - 10.08.2010, 23:35
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Brian_Furious - 10.08.2010, 23:53
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Carlton - 11.08.2010, 00:18
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by [LoD]Hauke - 14.08.2010, 23:23
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Carlton - 15.08.2010, 00:16
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by [LoD]Hauke - 15.08.2010, 00:52
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Carlton - 15.08.2010, 01:49
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by [LoD]Hauke - 15.08.2010, 19:32
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Carlton - 15.08.2010, 20:46
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by [LoD]Hauke - 15.08.2010, 22:30
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Carlton - 15.08.2010, 22:52
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by [LoD]Hauke - 15.08.2010, 22:55
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Brian_Furious - 15.08.2010, 23:13
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Carlton - 16.08.2010, 00:02
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Brian_Furious - 16.08.2010, 00:07
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Ace_Menace - 16.08.2010, 03:40
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Carlton - 16.08.2010, 04:07
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Ace_Menace - 16.08.2010, 07:03
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by RenisiL - 16.08.2010, 07:06
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Double-O-Seven - 16.08.2010, 16:43
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Carlton - 16.08.2010, 17:09
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Double-O-Seven - 16.08.2010, 17:12
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Carlton - 16.08.2010, 17:25
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Y_Less - 16.08.2010, 17:46
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Scenario - 16.08.2011, 02:34
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by TheBetaFox - 15.01.2012, 09:28
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Darnell - 11.07.2013, 10:03
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Y_Less - 11.07.2013, 10:11
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Darnell - 11.07.2013, 10:23
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by Darnell - 12.07.2013, 09:13
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by ReVson - 29.12.2017, 21:15
Re: C-MYSQL (Remade) - Increased Speed & More Simple - by JaKe Elite - 29.12.2017, 21:18

Forum Jump:


Users browsing this thread: 2 Guest(s)