If mysql connection failed try other connection?
#1

Heey all,

Is it possible if the connection is failed to the database to connect to another database?
Example: if the server cant connect to the local database connect to the hosted database.
How can i do this?

Admigo
Reply
#2

yes,
in MYSQL when you cant connect to the server/database it will return a connection handler which is 0 for Blug's.
But yes with that u can check if it's connected or not

soo.
pawn Code:
new mysql = mysql_connect("127.0.0.1","root","mydatabase","mypass");
if(mysql==0) return print("MySQL Connection not established!");
Reply
#3

Try something like this:
pawn Code:
mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
if(mysql_ping()>2)
mysql_connect(SQL2_HOST, SQL2_USER, SQL2_DB, SQL2_PASS);
Reply
#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


Forum Jump:


Users browsing this thread: 2 Guest(s)