Hello
Do you already have a policy on which problems an exception may be thrown
to the application (which most likely will cause its termination) and which
ones should be silently ignored?
For example, I found it very annoying to have found yet another case where
log4php simply did nothing and I had to debug deep down until I realized that
this time there was a typo in the SQL string.
This is a patch for enabling the Exception mode:
--- src/main/php/appenders/LoggerAppenderPDO.php (Revision 797911)
+++ src/main/php/appenders/LoggerAppenderPDO.php (Arbeitskopie)
@@ -78,6 +78,8 @@
$this->db = new PDO($this->dsn,$this->user,$this->password);
}
+ $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
// test if log table exists
$result = $this->db->query('select * from ' . $this->table . ' where 1
= 0');
if ($result == false and $this->createTable) {
My proposal would be to let PDO throw an Exception but at least to try a
reconnect if the current link has gone (which means that the application wont
die just because somebody restarted the database server). Log4perl does it
the same way.
As PDO has nothing like "mysql_ping()" and the
getAttribute(PDO::ATTR_CONNECTION_STATUS) does not give the current status,
a custom exception handler or some try/catches could be used... I try a bit
around if I find something suitable.
bye,
-christian-