Base layout of the core.
[platal.git] / classes / xdb.php
index 0523a96..a9cb068 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -27,7 +27,7 @@ class XDB
     {
         global $globals;
         XDB::$mysqli = new mysqli($globals->dbhost, $globals->dbuser, $globals->dbpwd, $globals->dbdb);
-        if ($globals->debug & 1) {
+        if ($globals->debug & DEBUG_BT) {
             $bt = new PlBacktrace('MySQL');
             if (mysqli_connect_errno()) {
                 $bt->newEvent("MySQLI connection", 0, mysqli_connect_error());
@@ -41,7 +41,7 @@ class XDB
 
     public static function _prepare($args)
     {
-        $query    = array_map(Array('XDB', '_db_escape'), $args);
+        $query    = array_map(Array('XDB', 'escape'), $args);
         $query[0] = str_replace('{?}', '%s', str_replace('%',   '%%', $args[0]));
         return call_user_func_array('sprintf', $query);
     }
@@ -79,7 +79,7 @@ class XDB
             return false;
         }
 
-        if ($globals->debug & 1) {
+        if ($globals->debug & DEBUG_BT) {
             $explain = array();
             if (strpos($query, 'FOUND_ROWS()') === false) {
                 $res = XDB::$mysqli->query("EXPLAIN $query");
@@ -95,7 +95,7 @@ class XDB
 
         $res = XDB::$mysqli->query($query);
 
-        if ($globals->debug & 1) {
+        if ($globals->debug & DEBUG_BT) {
             PlBacktrace::$bt['MySQL']->stop(@$res->num_rows ? $res->num_rows : XDB::$mysqli->affected_rows,
                                             XDB::$mysqli->error,
                                             $explain);
@@ -110,7 +110,12 @@ class XDB
 
     public static function execute()
     {
-        return XDB::_query(XDB::_prepare(func_get_args()));
+        global $globals;
+        $args = func_get_args();
+        if ($globals->mode != 'rw' && !strpos($args[0], 'logger')) {
+            return;
+        }
+        return XDB::_query(XDB::_prepare($args));
     }
 
     public static function iterator()
@@ -134,7 +139,7 @@ class XDB
     }
 
     public static function error()
-    {       
+    {
         return XDB::$mysqli->error;
     }
 
@@ -143,7 +148,7 @@ class XDB
         return XDB::$mysqli->affected_rows;
     }
 
-    public static function _db_escape($var)
+    public static function escape($var)
     {
         switch (gettype($var)) {
           case 'boolean':
@@ -161,6 +166,9 @@ class XDB
             return 'NULL';
 
           case 'object':
+            if ($var instanceof PlFlagSet) {
+                return "'" . addslashes($var->flags()) . "'";
+            }
           case 'array':
             return "'".addslashes(serialize($var))."'";