anewt-developers team mailing list archive
-
anewt-developers team
-
Mailing list archive
-
Message #00065
[Branch ~uws/anewt/anewt.uws] Rev 1686: [database] Handle MySQL connection errors more gracefully
------------------------------------------------------------
revno: 1686
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt.uws
timestamp: Sun 2009-07-19 21:42:51 +0200
message:
[database] Handle MySQL connection errors more gracefully
Throw AnewtDatabaseConnectionException instead of the
default ErrorException. This also avoids leaking the
database connection password as plaintext in debug
backtraces.
modified:
database/backend-mysql.lib.php
=== modified file 'database/backend-mysql.lib.php'
--- database/backend-mysql.lib.php 2009-07-18 16:51:09 +0000
+++ database/backend-mysql.lib.php 2009-07-19 19:42:51 +0000
@@ -68,13 +68,17 @@
$hostname = sprintf('p:%s', $hostname);
}
- $this->connection_handle = new MySQLi($hostname, $username, $password, $database);
-
- if (!$this->connection_handle)
- throw new AnewtDatabaseConnectionException('Could not connect to MySQL database');
-
- if ($encoding)
- $this->prepare_execute('SET NAMES ?str?', $encoding);
+ try
+ {
+ $this->connection_handle = @new MySQLi($hostname, $username, $password, $database);
+
+ if ($encoding)
+ $this->prepare_execute('SET NAMES ?str?', $encoding);
+ }
+ catch (Exception $e) {
+ throw new AnewtDatabaseConnectionException('Could not connect to MySQL database: %s', $e->getMessage());
+ }
+
}
protected function real_disconnect()
--
lp:anewt
https://code.launchpad.net/~uws/anewt/anewt.uws
Your team Anewt developers is subscribed to branch lp:anewt.
To unsubscribe from this branch go to https://code.launchpad.net/~uws/anewt/anewt.uws/+edit-subscription.