SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 16/11/2015, 08:53 PM   #61
kalanerik99
Huge Clucker
 
kalanerik99's Avatar
 
Join Date: Mar 2012
Location: Slovenia
Posts: 473
Reputation: 9
Default Re: Easy MySQL 1.0 - Simplifying the usage of MySQL queries!

Hey
How can I use boolean?
I think there isnt a constant but is there a way ?
Thanks
__________________


UGF
Unlimited GTA Freeroam

Freeroam - Deathmach - Race -Stunts



kalanerik99 is offline   Reply With Quote
Old 17/11/2015, 05:19 AM   #62
SecretBoss
Gangsta
 
SecretBoss's Avatar
 
Join Date: Dec 2014
Location: Greece
Posts: 807
Reputation: 106
Default Re: Easy MySQL 1.0 - Simplifying the usage of MySQL queries!

Quote:
Originally Posted by kalanerik99 View Post
Hey
How can I use boolean?
I think there isnt a constant but is there a way ?
Thanks
This is all you need

Code:
native SQL::WriteFloat(handle, const field[], Float:value);
native Float:SQL::GetFloatEntry(const table[], const field[], const column[], columnID, connectionHandle = 1);
native Float:SQL::GetFloatEntryEx(const table[], const field[], const column[], scolumn[], connectionHandle = 1);
native SQL::ReadFloat(handle, const field[], &Float:dest);
native SQL::UpdateFloatEntry(handle, const field[], Float:value);
native SQL::SetFloatEntry(const table[], const field[], Float:value, const column[], columnID, connectionHandle = 1);
native SQL::SetFloatEntryEx(const table[], const field[], Float:value, const column[], columnID[], connectionHandle = 1);
__________________

Last edited by SecretBoss; 29/11/2015 at 07:42 PM.
SecretBoss is offline   Reply With Quote
Old 13/12/2015, 11:05 PM   #63
F1N4L
High-roller
 
F1N4L's Avatar
 
Join Date: Jun 2013
Posts: 2,726
Reputation: 260
Default Re: Easy MySQL 1.0 - Simplifying the usage of MySQL queries!

Sorry, But There IS automatically creating a database , so the FS does not work!
What is the mysql plugin correct version ? I'm having trouble me connect to the server .

Last edited by F1N4L; 13/12/2015 at 11:39 PM.
F1N4L is offline   Reply With Quote
Old 14/12/2015, 11:21 AM   #64
SecretBoss
Gangsta
 
SecretBoss's Avatar
 
Join Date: Dec 2014
Location: Greece
Posts: 807
Reputation: 106
Default Re: Easy MySQL 2.0 - Simplifying the usage of MySQL queries!

Here you are

Quote:
Originally Posted by ThePhenix View Post
You need the MySQL plugin by BlueG.

MySQL Plugin

If you have any questions or suggestions, don't doubt on replying about it.
__________________
SecretBoss is offline   Reply With Quote
Old 06/01/2016, 03:32 AM   #65
vernz
Huge Clucker
 
vernz's Avatar
 
Join Date: Dec 2010
Posts: 230
Reputation: 6
Default Re: Easy MySQL 1.0 - Simplifying the usage of MySQL queries!

What would be the proper way to load all houses ?
vernz is offline   Reply With Quote
Old 06/01/2016, 04:56 AM   #66
Crayder
Banned
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,324
Reputation: 652
Default Re: Easy MySQL 1.0 - Simplifying the usage of MySQL queries!

Quote:
Originally Posted by vernz View Post
What would be the proper way to load all houses ?
Umm, this library has absolutely nothing to do with any house system. If you are using it for your house system then it's up to you to choose how you want to load it.
Crayder is offline   Reply With Quote
Old 06/01/2016, 05:41 AM   #67
vernz
Huge Clucker
 
vernz's Avatar
 
Join Date: Dec 2010
Posts: 230
Reputation: 6
Default Re: Easy MySQL 1.0 - Simplifying the usage of MySQL queries!

There should be a way or then mixing both
vernz is offline   Reply With Quote
Old 06/01/2016, 08:34 AM   #68
SecretBoss
Gangsta
 
SecretBoss's Avatar
 
Join Date: Dec 2014
Location: Greece
Posts: 807
Reputation: 106
Default Re: Easy MySQL 1.0 - Simplifying the usage of MySQL queries!

Quote:
Originally Posted by vernz View Post
What would be the proper way to load all houses ?
What I did for my old gamemode is to create a handle and use normal queries without this include

Code:
new HouseSQL;
stock SQL::Connect(const host[], const user[], const database[], const password[], bool:debugging = false, port = 3306, bool:autoreconnect = true, pool_size = 2)
{
	if(debugging == true) mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG);
	new SQL::mc;
	SQL::mc = mysql_connect(host, user, database, password, port, autoreconnect, pool_size);
	if(mysql_errno(SQL::mc) != 0)
	{
		SQL_Warning("Could not connect to database %s on host %s | user %s and password %s", database, host, user, password);
		return 0;
	
	}
	else
	{
	    SQL_Notice("Successfully connected to database!");
	}
	HouseSQL = SQL::mc;
	return SQL::mc;
}
Now you can use HouseSQL for your handles without using include's functions, now you can use something like this

Code:
mysql_tquery(HouseSQL, "SELECT * FROM houses", "LoadHouses", "");
Code:
forward LoadHouses()
public LoadHouses()
{
    new rows = cache_num_rows();
 	if(rows)
  	{
   		new houseid;
		for(new i; i < rows; i++)
		{
  			houseid = cache_get_field_content_int(i, "id");
		}
	}
}
__________________
SecretBoss is offline   Reply With Quote
Old 06/01/2016, 02:44 PM   #69
Max_Andolini
Huge Clucker
 
Max_Andolini's Avatar
 
Join Date: Oct 2013
Posts: 318
Reputation: 37
Default Re: Easy MySQL 1.0 - Simplifying the usage of MySQL queries!

Bugged:

stock SQL::RowExists(const table[], const column[], columnID[], connectionHandle = 1)

Change

stock SQL::RowExists(const table[], const column[], columnID, connectionHandle = 1)
Max_Andolini is offline   Reply With Quote
Old 05/02/2016, 08:49 AM   #70
Gasman
Little Clucker
 
Gasman's Avatar
 
Join Date: May 2015
Location: VietNam
Posts: 33
Reputation: 73
Default Re: Easy MySQL 1.0 - Simplifying the usage of MySQL queries!

Sorry but my script can not create new row in database
Successfully registered but no Insert to database.
pawn Code:
#include <a_samp>
#include <easymysql>
#define mysql_host    "localhost"
#define mysql_user    "root"
#define mysql_db        "xgtaz"
#define mysql_pass         "123456"
#define mysql_debugging_enabled             (true)

#define DIALOG_LOGIN 0
#define DIALOG_REGISTER 1
enum playerinfo
{
    pID,
    pPassword[64],
    pXP,
    pKills,
    pDeaths,
    pRank,
    pEvac,
    pAdminLevel,
    pVipLevel,
    pAdminDuty,
    pBanned,
    pCLeader,
    pCMember,
    pHour,
    pMin,
    pSec,
    pMapsPlayed,
    pCoins,
    pLogged,
    pWarnings,
    pPM,
    pBans,
    IsPlayerMuted,
    Killstreak,
    pHumanClass,
    pZombieClass,
    IsPlayerInfected,
    IsPlayerInfectedTimer,
    Boxes,
    BoxesAdvanced,
    C4,
    pVipKickBack,
    pVipFlash,
    pVipBoxes,
    pLadders,
    pRCcars,
    pKickBackCoin,
    pDamageShotgunCoin,
    pDamageDeagleCoin,
    pDamageMP5Coin,
    pDoctorShield,
    pXcoin,
};
new pInfo[MAX_PLAYERS][playerinfo];
main()
{
    print("\n----------------------------------");
    print(" ");
    print("----------------------------------\n");
}

public OnGameModeInit()
{
    SQL::Connect(mysql_host, mysql_user, mysql_db, mysql_pass);
    SetGameModeText("MYSQL SCRIPT");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    new handle = SQL::Open(SQL::CREATE, "players");
    SQL::AddTableEntry(handle, "p_id", SQL_TYPE_INT, 11, true);
    SQL::AddTableEntry(handle, "p_name", SQL_TYPE_VCHAR, 24);
    SQL::AddTableEntry(handle, "p_ip", SQL_TYPE_VCHAR, 16);
    SQL::AddTableEntry(handle, "p_password", SQL_TYPE_VCHAR, 64);
    SQL::AddTableEntry(handle, "p_xp", SQL_TYPE_INT);
    SQL::AddTableEntry(handle, "p_kills", SQL_TYPE_INT);
    SQL::AddTableEntry(handle, "p_rank", SQL_TYPE_INT);
    SQL::AddTableEntry(handle, "p_evac", SQL_TYPE_INT);
    SQL::AddTableEntry(handle, "p_adminlevel", SQL_TYPE_INT);
    SQL::AddTableEntry(handle, "p_viplevel", SQL_TYPE_INT);
    SQL::AddTableEntry(handle, "p_adminduty", SQL_TYPE_INT);
    SQL::AddTableEntry(handle, "p_banned", SQL_TYPE_INT);
    SQL::AddTableEntry(handle, "p_cleader", SQL_TYPE_INT);
    SQL::AddTableEntry(handle, "p_cmember", SQL_TYPE_INT);
    SQL::AddTableEntry(handle, "p_hour", SQL_TYPE_INT);
    SQL::AddTableEntry(handle, "p_min", SQL_TYPE_INT);
    SQL::AddTableEntry(handle, "p_sec", SQL_TYPE_INT);
    SQL::AddTableEntry(handle, "p_mapsplayed", SQL_TYPE_INT);
    SQL::AddTableEntry(handle, "p_coins", SQL_TYPE_INT);
    SQL::AddTableEntry(handle, "p_xcoins", SQL_TYPE_INT);
    SQL::Close(handle);
    return 1;
}

stock ret_pName(playerid)
{
    new name[24];
    GetPlayerName(playerid, name, sizeof(name));
    return name;
}
public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}

public OnPlayerConnect(playerid)
{
    if(SQL::RowExistsEx("players", "p_name", ret_pName(playerid))) //Check if the name is registered in the database
    {
        new handle = SQL::OpenEx(SQL::READ, "players", "p_name", ret_pName(playerid));
        SQL::ReadString(handle, "p_password", pInfo[playerid][pPassword], 64);
        SQL::ReadInt(handle, "p_id", pInfo[playerid][pID]);
        SQL::Close(handle);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{0080FF}Login", "Please input your password below to log in.", "Login", "Exit");
    }
    else
    {
        //If not registered, then show the register DIALOG.
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{0080FF}Register", "Please input a password below to register in.", "Reg", "Exit");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(pInfo[playerid][pLogged] == 1)
    {
        new handle = SQL::Open(SQL::UPDATE, "players", "p_id", pInfo[playerid][pID]);
        SQL::WriteInt(handle,"p_xp",pInfo[playerid][pXP]);
        SQL::WriteInt(handle,"p_kills",pInfo[playerid][pKills]);
        SQL::WriteInt(handle,"p_deaths",pInfo[playerid][pDeaths]);
        SQL::WriteInt(handle,"p_rank",pInfo[playerid][pRank]);
        SQL::WriteInt(handle,"p_evac",pInfo[playerid][pEvac]);
        SQL::WriteInt(handle,"p_banned",pInfo[playerid][pBanned]);
        SQL::WriteInt(handle,"p_cleader",pInfo[playerid][pCLeader]);
        SQL::WriteInt(handle,"p_cmember",pInfo[playerid][pCMember]);
        SQL::WriteInt(handle,"p_adminlevel",pInfo[playerid][pAdminLevel]);
        SQL::WriteInt(handle,"p_viplevel",pInfo[playerid][pVipLevel]);
        SQL::WriteInt(handle,"p_adminduty",pInfo[playerid][pAdminDuty]);
        SQL::WriteInt(handle,"p_hour",pInfo[playerid][pHour]);
        SQL::WriteInt(handle,"p_min",pInfo[playerid][pMin]);
        SQL::WriteInt(handle,"p_sec",pInfo[playerid][pSec]);
        SQL::WriteInt(handle,"p_mapsplayed",pInfo[playerid][pMapsPlayed]);
        SQL::WriteInt(handle,"p_coins",pInfo[playerid][pCoins]);
        SQL::WriteInt(handle,"p_xcoin",pInfo[playerid][pXcoin]);
        SQL::Close(handle);
    }
    return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_REGISTER:
        {
            if(!response) return Kick(playerid);
            if(strlen(inputtext) < 5)
            {
                ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{0080FF}Register", "Please input a password below to register in.", "Login", "Exit");
                return 1;
            }
            SHA256_PassHash(inputtext, "", pInfo[playerid][pPassword], 64);
            new handle = SQL::Open(SQL::INSERT, "players");
            SQL::ToggleAutoIncrement(handle, true);//Toggles auto increment, SQL::Close will return cache_insert_id();
            SQL::WriteString(handle, "p_name", ret_pName(playerid));
            SQL::WriteString(handle, "p_password", pInfo[playerid][pPassword]);
            SQL::WriteInt(handle,"p_xp",0);
            SQL::WriteInt(handle,"p_kills",0);
            SQL::WriteInt(handle,"p_deaths",0);
            SQL::WriteInt(handle,"p_rank",0);
            SQL::WriteInt(handle,"p_evac",0);
            SendClientMessage(playerid, -1, "Write!");
            SQL::WriteInt(handle,"p_adminlevel",0);
            SQL::WriteInt(handle,"p_viplevel",0);
            SQL::WriteInt(handle,"p_adminduty",0);
            SQL::WriteInt(handle,"p_hour",0);
            SQL::WriteInt(handle,"p_min",0);
            SQL::WriteInt(handle,"p_sec",0);
            SQL::WriteInt(handle,"p_mapsplayed",0);
            SQL::WriteInt(handle,"p_coins",0);
            SQL::WriteInt(handle,"p_banned",0);
            SQL::WriteInt(handle,"p_cleader",0);
            SQL::WriteInt(handle,"p_cMember",0);
            SQL::WriteInt(handle,"p_bans",0);
            SQL::WriteInt(handle,"p_xcoin",0);
            SQL::WriteString(handle, "p_ip","127.0.0.1");
            pInfo[playerid][pID] = SQL::Close(handle);
            SendClientMessage(playerid, -1, "Successfully registered in!");
            pInfo[playerid][pLogged] = 1;
        }
        case DIALOG_LOGIN:
        {
            if(!response) Kick(playerid);
            new hash[64];
            SHA256_PassHash(inputtext, "", hash, 64);
            if(!strcmp(hash, pInfo[playerid][pPassword]))
            {
                //Load player data
                new handle = SQL::Open(SQL::READ, "players", "p_id", pInfo[playerid][pID]);
                SQL::ReadInt(handle, "p_xp",pInfo[playerid][pXP]);
                SQL::ReadInt(handle, "p_kills",pInfo[playerid][pKills]);
                SQL::ReadInt(handle, "p_deaths",pInfo[playerid][pDeaths]);
                SQL::ReadInt(handle, "p_rank",pInfo[playerid][pRank]);
                SQL::ReadInt(handle, "p_evac",pInfo[playerid][pEvac]);
                SQL::ReadInt(handle, "p_adminlevel",pInfo[playerid][pAdminLevel]);
                SQL::ReadInt(handle, "p_viplevel",pInfo[playerid][pVipLevel]);
                SQL::ReadInt(handle, "p_adminduty",pInfo[playerid][pAdminDuty]);
                SQL::ReadInt(handle, "p_hour",pInfo[playerid][pHour]);
                SQL::ReadInt(handle, "p_min",pInfo[playerid][pMin]);
                SQL::ReadInt(handle, "p_sec",pInfo[playerid][pSec]);
                SQL::ReadInt(handle, "p_mapsplayed",pInfo[playerid][pMapsPlayed]);
                SQL::ReadInt(handle, "p_coins",pInfo[playerid][pCoins]);
                SQL::ReadInt(handle, "p_banned",pInfo[playerid][pBanned]);
                SQL::ReadInt(handle, "p_cleader",pInfo[playerid][pCLeader]);
                SQL::ReadInt(handle, "p_cmember",pInfo[playerid][pCMember]);
                SQL::ReadInt(handle, "p_bans",pInfo[playerid][pBans]);
                SQL::ReadInt(handle, "p_xcoin",pInfo[playerid][pXcoin]);
                SQL::Close(handle);
                pInfo[playerid][pLogged] = 1;
                SendClientMessage(playerid, -1, "Successfully logged in!");

            }
            else
            {
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{0080FF}Login", "Please input your password below to log in.", "Login", "Exit");
            }
        }
    }
    return 1;
}
Gasman is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Queries Terrorizt Scripting Help 3 05/07/2015 03:42 PM
[Tutorial] MySQL-queries iRaiDeN Tutorials 2 21/03/2014 03:20 PM
Many mySQL queries MP2 Scripting Help 9 09/04/2013 12:49 AM
Help with MySQL queries LiamM Scripting Help 4 20/03/2013 10:37 AM


All times are GMT. The time now is 09:16 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.