SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 01/07/2019, 08:06 PM   #1
Nickk888
Little Clucker
 
Nickk888's Avatar
 
Join Date: Oct 2011
Location: Germany
Posts: 34
Reputation: 37
Thumbs up MySQL Connector (BlueG) - Easily connect to your Database!

Hello everybody, i made a very small include because i'm lazy and i like to speed up my coding process

This include contains about 35 lines of code(Without the credits).

It was made to make a faster connection to a database with all the checks and prints, it's great if you want to create a new MySQL based script and create a connection fast.

Functions:
Code:
MySQL_Connect(scriptname[], &MySQL:handleid, contype = MYSQL_CONNECT_TYPE_FILE, hostname[] = "", username[] = "", password[] = "", database[] = "", filename[] = "mysql.ini");
Code:
MySQL_Disconnect(MySQL:mysql_handle);
Defines:
Code:
MYSQL_CONNECT_TYPE_NORMAL
MYSQL_CONNECT_TYPE_FILE
How to use(Example):
Code:
#include <a_samp>
#include <a_mysql>
#include <a_mysql-connector>

new MySQL:SQL_Handle;

public OnFilterScriptInit()
{
	MySQL_Connect("SCRIPT NAME", SQL_Handle);
	return 1;
}

public OnFilterScriptExit()
{
	MySQL_Disconnect(SQL_Handle);
	return 1;
}
Include:
Code:
/*
Include: a_mysql-connector
Author: Nickk888
Dependencies: MySQL BlueG >=R33
*/

#define MYSQL_CONNECT_TYPE_NORMAL 0
#define MYSQL_CONNECT_TYPE_FILE 1

stock MySQL_Connect(scriptname[], &MySQL:handleid, contype = MYSQL_CONNECT_TYPE_FILE, hostname[] = "", username[] = "", password[] = "", database[] = "", filename[] = "mysql.ini")
{
	switch(contype)
	{
		case MYSQL_CONNECT_TYPE_NORMAL: handleid = mysql_connect(hostname, username, password, database);
		case MYSQL_CONNECT_TYPE_FILE: handleid = mysql_connect_file(filename);
	}
	if(handleid == MYSQL_INVALID_HANDLE || mysql_errno(handleid) != 0)
	{
		printf("[%s - MySQL] connection to the database could not be established!", scriptname);
		printf("[%s - MySQL] Check your data!", scriptname);
		handleid = MYSQL_INVALID_HANDLE;
		return 0;
	}
	else
	{
		printf("[%s - MySQL] The connection has been established.", scriptname);
	}
	return 1;
}

stock MySQL_Disconnect(MySQL:mysql_handle)
{
	if(mysql_handle != MYSQL_INVALID_HANDLE || mysql_errno(mysql_handle) == 0)
	{
		mysql_close(mysql_handle);
		return 1;
	}
	return 0;
}
Like a said, it's for the lazy ones But if you write a new MySQL Based script every week, you just get sick to code the same thing again and again XD
Have fun :P
__________________
Nickk888 is online now   Reply With Quote
Old 01/07/2019, 08:07 PM   #2
Robson04
Big Clucker
 
Robson04's Avatar
 
Join Date: Aug 2018
Posts: 66
Reputation: 0
Default Re: MySQL Connector (BlueG) - Easily connect to your Database!

Nice.
Good job.
Robson04 is offline   Reply With Quote
Old 01/07/2019, 08:11 PM   #3
Dayrion
High-roller
 
Dayrion's Avatar
 
Join Date: Jan 2016
Location: France
Posts: 1,920
Reputation: 258
Default Re: MySQL Connector (BlueG) - Easily connect to your Database!

Tbh, that's completly useless. What's the main purpose of this include?
__________________
actor_plus - v5.0.2
I'm a goner, somebody catch my breath,
I'm a goner, somebody catch my breath
Dayrion is offline   Reply With Quote
Old 01/07/2019, 08:13 PM   #4
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,765
Reputation: 840
Default Re: MySQL Connector (BlueG) - Easily connect to your Database!

What is the advantage of using this over regular mysql_connect?!
__________________

Follow me on Github: Follow me on Spotify: Donate on Paypal:

Gammix is offline   Reply With Quote
Old 01/07/2019, 08:16 PM   #5
Nickk888
Little Clucker
 
Nickk888's Avatar
 
Join Date: Oct 2011
Location: Germany
Posts: 34
Reputation: 37
Default Re: MySQL Connector (BlueG) - Easily connect to your Database!

Did you read that text above? It will speed up the process to establish a connection without checking if there is a connection or not and so you don't have to create prints to get a message on the console, it's all automatic.

It's made for the lazy programmers like me to have something that will speed up my coding process even if that's a few seconds or minutes. If you create a MySQL based script and you need to create a connection fast, you just use one single line of code, and it'll try to make a connection, check if there is and print the result in the console window and returning the handleid.
__________________
Nickk888 is online now   Reply With Quote
Old 01/07/2019, 10:19 PM   #6
Hazon
Big Clucker
 
Hazon's Avatar
 
Join Date: May 2018
Location: Who cares ?
Posts: 145
Reputation: 25
Default Re: MySQL Connector (BlueG) - Easily connect to your Database!

No thanks. I'm good with what we have.
Hazon is online now   Reply With Quote
Old 01/07/2019, 10:59 PM   #7
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,179
Reputation: 404
Default Re: MySQL Connector (BlueG) - Easily connect to your Database!

Wow thanks, i used this on my dog and now its a whale
__________________
Quote:
Originally Posted by Andy
My anti cheat is still relevant *puts shades on* https://github.com/RogueDrifter/Anti_cheat_pack

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link
RogueDrifter is offline   Reply With Quote
Old 02/07/2019, 07:09 AM   #8
SiaReyes
Huge Clucker
 
SiaReyes's Avatar
 
Join Date: Mar 2019
Location: Coordinates X,Y,Z
Posts: 323
Reputation: 22
Default Re: MySQL Connector (BlueG) - Easily connect to your Database!

Lol tf is this? Pretty useless there is no big difference in yours and the original code. I'll simply go with the original include. Actually, just for 2 lines for connection & disconnection why i use this 35 lines code?
__________________
Offshowtime Fuck It!

Quote:
Originally Posted by Toroi View Post
blackmail people that join your server using their ip address as hostage

or get a job and play sa-mp for fun
SiaReyes 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 can't connect database [S-G]Cypher Scripting Help 0 03/10/2015 02:34 PM
MySQL database can't connect. [rG]Cold Server Support 0 28/09/2015 11:36 AM
Can't connect to mysql database.. Ox1gEN Scripting Help 45 28/08/2014 04:41 AM
MySQL won't connect to my database Rocky2k12 Server Support 5 17/04/2014 03:39 PM
How to connect mysql server with custom port?(using BlueG's plugin R6_2) yxliang Scripting Help 2 26/01/2013 05:07 PM


All times are GMT. The time now is 09:11 PM.


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