SA-MP Forums Archive
MySQL Connect - 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: MySQL Connect (/showthread.php?tid=655974)



MySQL Connect - KamilPolska - 04.07.2018

How to connect MySQL StrickenKid?
Code:
new MySQL:connection;

MySQL_Connect()
{
              connection = mysql_init(LOG_ONLY_ERRORS, 1); 
              mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DATA, connection, 1);

	if() // What to add?
	{
              // Connect MySQL
	}
	else
	{
              // No connect MySQL
	}
	return 1;
}



Re: MySQL Connect - kovac - 04.07.2018

PHP Code:
// :: MySQL Database
#define MYSQL_HOST                 "localhost"
#define MYSQL_USER                 "root"
#define MYSQL_PASS                 ""
#define MYSQL_DATABASE             "server"
new MySQLDatabase;
// OnGameModeInit
new MySQLOptoption_id mysql_init_options();
mysql_set_option(option_idAUTO_RECONNECTtrue); // We will set that option to automatically reconnect on timeouts.
Database mysql_connect(MYSQL_HOSTMYSQL_USERMYSQL_PASSMYSQL_DATABASEoption_id);
if(
Database == MYSQL_INVALID_HANDLE || mysql_errno(Database) != 0// Checking if the database connection is invalid to shutdown.
{
    print(
"Connection to MySQL database has failed. Shutting down the server.");
    
printf("[DEBUG] Host: %s, User: %s, Password: %s, Database: %s"MYSQL_HOSTMYSQL_USERMYSQL_PASSMYSQL_DATABASE);
    
SendRconCommand("exit");
    return 
1;