コード例 #1
0
ファイル: Mysql.php プロジェクト: akulygina/kuhni-podolsk
 /**
  * @param $sql
  * @return bool|\mysqli_result
  * @throws Exception
  */
 public function query($sql)
 {
     parent::query($sql);
     $result = mysqli_query($this->handler, $this->query);
     if (!$result) {
         throw new Exception(SQL_RESULT_FALSE);
     }
     if (!is_bool($result)) {
         #$result->free();
         mysqli_free_result($result);
     }
     return $result;
 }
コード例 #2
0
ファイル: Model.php プロジェクト: bkb24/mvc
 public static function get()
 {
     $sql = "SELECT * FROM " . self::getInstance()->table;
     $where;
     $order;
     $limit;
     if (self::$where === null) {
         $where = ' ';
     } else {
         $where = " WHERE ";
         $all = array();
         foreach (self::$where as $key => $value) {
             $all[] = implode(" ", $value);
         }
         if (count($all) > 1) {
             $where .= implode(" AND ", $all);
         } else {
             $where .= $all[0];
         }
     }
     if (self::$order === null) {
         $order = ' ';
     } else {
         $order = " ORDER BY ";
         $all = implode(", ", self::$order);
         $order .= $all;
     }
     if (self::$limit === null) {
         if (self::$offset === null) {
             $limit = ' ';
         } else {
             $bigint = 1.8446744073709552E+19;
             $limit = " LIMIT " . self::$offset . ", " . $bigint;
         }
     } else {
         if (self::$offset === null) {
             $limit = " LIMIT " . self::$limit;
         } else {
             $limit = " LIMIT " . self::$offset . ", " . self::$limit;
         }
     }
     $sql .= $where . $order . $limit;
     $rows = array();
     if ($result = DB::query($sql)) {
         while ($row = $result->fetch_object()) {
             $rows[] = new self::$_class($row);
         }
         $result->close();
     } else {
         echo "Connection Error!";
     }
     self::$where = null;
     self::$order = null;
     self::$limit = null;
     self::$offset = null;
     return $rows;
 }