SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 01/07/2019, 07:06 PM   #1
Nickk888
Little Clucker
 
Nickk888's Avatar
 
Join Date: Oct 2011
Location: Germany
Posts: 28
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 offline   Reply With Quote
Old 01/07/2019, 07:07 PM   #2
Robson04
Big Clucker
 
Robson04's Avatar
 
Join Date: Aug 2018
Posts: 55
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, 07:11 PM   #3
Dayrion
High-roller
 
Dayrion's Avatar
 
Join Date: Jan 2016
Location: France
Posts: 1,921
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, 07:13 PM   #4
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,761
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, 07:16 PM   #5
Nickk888
Little Clucker
 
Nickk888's Avatar
 
Join Date: Oct 2011
Location: Germany
Posts: 28
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 offline   Reply With Quote
Old 01/07/2019, 09:19 PM   #6
Hazon
Big Clucker
 
Hazon's Avatar
 
Join Date: May 2018
Location: Who cares ?
Posts: 116
Reputation: 11
Default Re: MySQL Connector (BlueG) - Easily connect to your Database!

No thanks. I'm good with what we have.
Hazon is offline   Reply With Quote
Old 01/07/2019, 09:59 PM   #7
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,202
Reputation: 390
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
I offer paid scripting services, I can do anything except mapping because fuck mapping.

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link
RogueDrifter is offline   Reply With Quote
Old 02/07/2019, 06:09 AM   #8
SiaReyes
Huge Clucker
 
SiaReyes's Avatar
 
Join Date: Mar 2019
Location: Coordinates X,Y,Z
Posts: 299
Reputation: 20
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?
__________________
Hey guys,
We've just started up our own hosting company and we are offering cheap game hosting. Our SAMP servers start at only $0.50 cents for 32 slots per month, or $1.50 for 64. We have ONE FREE spot left for a first month free subscription for any game host of your choice. We host most many major games such as SAMP, Call of Duty, 7 Days to Die, Minecraft, CounterStrike, ARK: Survival Evolved, and many more!

Cheapest hosting company official site : http://main-hosts.com/

Cheap Hosting Company is looking for an experience staff.

Sign up to our forums and Control Panel and order one of our cheap game servers. First to sign up will receive a free SA:MP server! Join on discord https://discord.gg/J82JgQJ for more information!

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


All times are GMT. The time now is 08:02 AM.


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