If mysql connection failed try other connection?
#4

Assuming you use blueg's mysql plugin
pawn Code:
// At the top \\

new gConn;

#define SQL_HOST_LOCAL "hostname"
#define SQL_USER_LOCAL "user"
#define SQL_PASS_LOCAL "password"
#define SQL_DB_LOCAL "database_name"

#define SQL_HOST_HOST "hostname"
#define SQL_USER_HOST "user"
#define SQL_PASS_HOST "password"
#define SQL_DB_HOST "database_name"

// Anywhere you want(Then add mySQL_init(); in OnGameModeInit callback) \\

stock mySQL_init()
{
    gConn = mysql_connect(SQL_HOST_LOCAL, SQL_USER_LOCAL, SQL_DB_LOCAL, SQL_PASS_LOCAL);

    if(mysql_ping() > 0) {
        printf("» Successfully connected to local database [%s].",SQL_DB_LOCAL);
    }
    else {
        print("» Couldn't connect to local database.");
        gConn = mysql_connect(SQL_HOST_HOST, SQL_USER_HOST, SQL_DB_HOST, SQL_PASS_HOST);
        if(mysql_ping() > 0) {
            printf("» Successfully connected to hosted database [%s].",SQL_DB_HOST);
        } else {
            printf("» Couldn't connect to any of the databases.Closing server...");
            SendRconCommand("exit");
        }
    }
    return 1;
}
Should work :d

Edit->Too slow
Reply


Messages In This Thread
If mysql connection failed try other connection? - by Admigo - 25.03.2013, 16:43
Re: If mysql connection failed try other connection? - by park4bmx - 25.03.2013, 16:50
Re: If mysql connection failed try other connection? - by reckst4r - 25.03.2013, 16:53
Re: If mysql connection failed try other connection? - by InfiniTy. - 25.03.2013, 16:54

Forum Jump:


Users browsing this thread: 1 Guest(s)