public function execute()
 {
     $t1 = microtime(true);
     //TODO redo this with hooks that cached classes can use.
     if ((DB_USE_MEMCACHE || DB_USE_QCACHE) && strtolower(substr($this->sql, 0, 6)) != 'select' && strtolower(substr($this->sql, 0, 4)) != 'show') {
         $qc = DBFactory::getDBQuery();
         $qc->markAffectedTables($this->sql);
     }
     if (!$this->stmt->execute()) {
         if (defined('KB_PROFILE')) {
             DBDebug::recordError("SQL execution error: " . $this->stmt->error);
             DBDebug::recordError("SQL: " . $this->sql);
         }
         throw new Exception("SQL Execution error: " . $this->stmt->error . " Query: " . $this->sql);
     }
     $this->stmt->store_result();
     $this->exectime = microtime(true) - $t1;
     self::$totalexectime += $this->exectime;
     $this->executed = true;
     return true;
 }
 /**
  * Return the total number of rows returned by the last query (if there were no limits).
  *
  * @return int
  */
 public function totalRecordCount()
 {
     $res = mysqli_query(self::$dbconn->id(), "SELECT FOUND_ROWS()");
     if ($this->resid === false || self::$dbconn->id()->errno) {
         if (defined('KB_PROFILE')) {
             DBDebug::recordError("Database error: " . self::$dbconn->id()->error);
             DBDebug::recordError("SQL: " . $sql);
         }
         if (defined('DB_HALTONERROR') && DB_HALTONERROR) {
             echo "Database error: " . self::$dbconn->id()->error . "<br />";
             echo "SQL: " . $sql . "<br />";
             trigger_error("SQL error (" . self::$dbconn->id()->error, E_USER_ERROR);
             exit;
         } else {
             trigger_error("SQL error (" . self::$dbconn->id()->error, E_USER_WARNING);
             return false;
         }
     }
     $row = $res ? $res->fetch_row() : false;
     $total = $row[0];
     return $total;
 }
 /**
  * Set the autocommit status.
  * The default of true commits after every query.
  * If set to false the queries will not be commited until autocommit is set
  * to true.
  *  @param boolean $commit The new autocommit status.
  *  @return mixed true on success and false on failure.
  */
 function autocommit($commit = true)
 {
     if (defined('KB_PROFILE') && KB_PROFILE == 3) {
         if (!$commit) {
             DBDebug::recordError("Transaction started.");
         } else {
             DBDebug::recordError("Transaction ended.");
         }
     }
     return self::$dbconn->id()->autocommit($commit);
 }