From: Florent Bruneau Date: Tue, 24 Jun 2008 20:39:18 +0000 (+0200) Subject: SQL error MUST NOT happen... so stop the execution of if an SQL error is X-Git-Tag: core/1.0.0~67 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=084a60da013242606a81154e49257ab3ff51713f;p=platal.git SQL error MUST NOT happen... so stop the execution of if an SQL error is 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 --- diff --git a/classes/xdb.php b/classes/xdb.php index a9cb068..19786b4 100644 --- a/classes/xdb.php +++ b/classes/xdb.php @@ -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; }