01.03.2012, 19:22
If you enter wrong DB, debug will write this:
If you try to execute a query after failed connection, it will write "Dead connection".
So, you can use mysql_ping() because it isn't connected to a MySQL server.
It works for wrong username/pass AND wrong DB.
Код:
[21:20:43] >> mysql_connect(localhost, root, wrong_db, ******) on port 3306 [21:20:43] CMySQLHandler::CMySQLHandler() - constructor called. [21:20:43] CMySQLHandler::CMySQLHandler() - Connecting to "localhost" | DB: "wrong_db" | Username: "root" [21:20:43] CMySQLHandler::Connect() - Unknown database 'wrong_db' (Error ID: 1049) [21:20:43] >> mysql_ping( Connection handle: 1 )
So, you can use mysql_ping() because it isn't connected to a MySQL server.
pawn Код:
if(mysql_ping() == -1) print("Connection failed");