Example #1
0
 /**
  * Performs the request query as a prepared statement and returns the results in the format constant specified:
  * 		DB_QQ_FULL				Returns an indexed array of column named arrays for all rows returned.
  * 		DB_QQ_SINGLE_ROW		Returns a column named array of the first row returned
  * 		DB_QQ_SINGLE_COLUMN		Returns an indexed array of all row results in the first column
  * 		DB_QQ_SINGLE_CELL		Returns a string containing the first column of the first row
  *
  * @param string $query The SQL query to perform.
  * @param array $data Array containing the bound parameters
  * @param integer $mode Format to return the requested data as.
  * @return array|string
  * @static
  */
 public static function PreparedQuery($query, $data, $mode = DB_QQ_FULL)
 {
     $pdo = self::Link();
     self::$lastQuery = $query;
     if (self::$query_callback && is_callable(self::$query_callback)) {
         call_user_func(self::$query_callback, $query);
     }
     self::$lastResult = $pdo->prepare($query);
     self::$lastResult->execute($data);
     $c = self::TotalResults();
     switch ((int) $mode) {
         case DB_QQ_NONE:
             return $c;
         case DB_QQ_SINGLE_ROW:
             return $c ? self::$lastResult->fetch(PDO::FETCH_ASSOC) : array();
         case DB_QQ_SINGLE_COLUMN:
             return $c ? self::$lastResult->fetchAll(PDO::FETCH_COLUMN, 0) : array();
         case DB_QQ_SINGLE_CELL:
             if ($c) {
                 $row = self::$lastResult->fetch(PDO::FETCH_NUM);
                 return $row[0];
             } else {
                 return null;
             }
         case DB_QQ_FULL:
         default:
             return $c ? self::$lastResult->fetchAll(PDO::FETCH_ASSOC) : array();
     }
 }