SA-MP Forums Archive
Connect database with gamemode - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Connect database with gamemode (/showthread.php?tid=646689)



Connect database with gamemode - Wesmokady - 21.12.2017

Good community samp, this time I come with a very simple question for many but complicated for me. I do not know how to connect my mysql database with the gamemode, and followed steps on the internet which have not helped me, who can help me I will be very grateful because it is for my new project roleplay, thank you very much for your attention and I hope your collaboration


Re: Connect database with gamemode - Lucases - 21.12.2017

https://sampwiki.blast.hk/wiki/MySQL#mysql_connect

You should define at the top of your script your mysql credentials

pawn Код:
#define MYSQL_HOST "127.0.0.1c
#define MYSQL_USERNAME "root"
#define MYSQL_PASSWORD "password"
#define MYSQL_DATABASE "yourdatabase"

new MySQL:database;


public OnGamemodeModeInit()
{
     database = mysql_connect(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD, MYSQL_DATABASE);
     return 1;
}
You'll have to change these credentials to your mysql database's ones



pawn Код:
new MySQL:database;
This is needed to store the mysql handle. you need it to use mysql_tquery and etc..


After that you simply use mysql_connect function

pawn Код:
database = mysql_connect(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD, MYSQL_DATABASE);
Here we get the mysql handle and put it inside database variable