SQL error MUST NOT happen... so stop the execution of if an SQL error is
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 24 Jun 2008 20:39:18 +0000 (22:39 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 24 Jun 2008 20:39:18 +0000 (22:39 +0200)
found.

Why ?
I've found too many invisible SQL errors during the last few weeks
(invisible == not shown in a backtrace because of a page redirection). SQL
errors are evil (hum), they should NEVER happen: a query that is allowed to
fail can always been rewritten in a way errors are ignored (e.g. INSERT
IGNORE).

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/xdb.php

index a9cb068..19786b4 100644 (file)
@@ -76,7 +76,8 @@ class XDB
         global $globals;
 
         if (!XDB::$mysqli && !XDB::connect()) {
-            return false;
+            Platal::page()->kill('Impossible de se connecter à la base de données.');
+            exit;
         }
 
         if ($globals->debug & DEBUG_BT) {
@@ -100,6 +101,16 @@ class XDB
                                             XDB::$mysqli->error,
                                             $explain);
         }
+
+        if ($res === false) {
+            if (strpos($query, 'INSERT') === false && strpos($query, 'UPDATE') === false
+                && strpos($query, 'REPLACE') === false && strpos($query, 'DELETE') === false) {
+                Platal::page()->kill('Erreur lors de l\'interrogation de la base de données');
+            } else {
+                Platal::page()->kill('Erreur lors de l\'écriture dans la base de données');
+            }
+            exit;
+        }
         return $res;
     }