SA-MP Forums Archive
MySQL connection always failed! - 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 connection always failed! (/showthread.php?tid=629527)



MySQL connection always failed! - DuyDang2412 - 28.02.2017

Hello guys, I'm learning about MySQL and I always get my connection failed.
PHP код:
#define MYSQL_HOST                                    "localhost"
#define MYSQL_USER                                    "root"
#define MYSQL_DATABASE                                "dbbase"
#define MYSQL_PASSWORD                                "123456"
ConnectMySQL(){ 
    
MHandle mysql_connect(MYSQL_HOSTMYSQL_USERMYSQL_DATABASEMYSQL_PASSWORD);
    if(
mysql_errno() != 0){
        print(
"[MYSQL] The connection was failed.");
        
printf("[MYSQL] Host : %s | User : %s | Database : %s | Password : %s"MYSQL_HOSTMYSQL_USERMYSQL_DATABASEMYSQL_PASSWORD);
    }else {
        print(
"[MYSQL] The connection was succesful.");
        
//SendRconCommand("exit");
    
}



I am using MySQL 5.5, MySQL Plugin R41-2, the lastest version.


Re: MySQL connection always failed! - X337 - 28.02.2017

Correct parameters for mysql_connect in R40+ are
Код:
mysql_connect(const host[], const user[], const password[], const database[], MySQLOpt:option_id = MySQLOpt:0)
just switch between MYSQL_DATABASE and MYSQL_PASSWORD in your code
Код:
mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);
https://sampwiki.blast.hk/wiki/MySQL/R40#mysql_connect


Re: MySQL connection always failed! - DuyDang2412 - 28.02.2017

It worked, thank you very much. REP+!


Re: MySQL connection always failed! - Dayrion - 28.02.2017

edit: .