Connect database with gamemode
#1

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
Reply
#2

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)