Example #1
0
 public function getByColumn($field, $value)
 {
     $sql = 'SELECT * FROM ' . static::$table . ' WHERE ' . $field . '=:value';
     $DB = new DB();
     $DB->setClassName(get_called_class());
     return $DB->query($sql, [':value' => $value]);
 }
Example #2
0
 public function findAll()
 {
     echo $class = get_called_class();
     $sql = 'SELECT * FROM' . static::$table;
     $db = new DB();
     $db->setClassName($class);
     return $db->query($sql);
 }
Example #3
0
 public static function findOneByPk($id)
 {
     $class = get_called_class();
     $sql = 'SELECT * FROM ' . static::$table . ' WHERE id=:id';
     $db = new DB();
     $db->setClassName($class);
     return $db->query($sql, [':id' => $id])[0];
 }
Example #4
0
 public static function findUsersOne($id)
 {
     $class = get_called_class();
     $sql = "SELECT * FROM " . static::$table . " WHERE user_id = :id";
     $db = new DB();
     $db->setClassName($class);
     return $db->query($sql, [":id" => $id])[0];
 }
Example #5
0
 public static function findOneByField($field, $value)
 {
     $class = get_called_class();
     $sql = 'SELECT * FROM ' . static::$table . ' WHERE ' . $field . '=:value';
     $db = new DB();
     $db->setClassName($class);
     return $db->query($sql, [':value' => $value])[0];
 }
Example #6
0
 public static function getOneAd($id)
 {
     $sql = "SELECT * FROM adverts WHERE id=" . $id;
     $db = new DB();
     $class = get_called_class();
     $db->setClassName($class);
     $data = $db->query($sql);
     return $data[0];
 }
Example #7
0
 public static function findOneByColumn($column, $value)
 {
     $class = get_called_class();
     $db = new DB();
     $db->setClassName($class);
     $query = "SELECT * FROM " . static::$table . " WHERE " . $column . "=:value";
     $res = $db->query($query, [':value' => $value]);
     return $res[0];
 }
Example #8
0
 public static function findByColumn($col, $val)
 {
     $sql = 'SELECT * FROM ' . static::$table . ' WHERE ' . $col . '=:val';
     $db = new DB();
     $db->setClassName(get_called_class());
     $res = $db->query($sql, [':val' => $val]);
     if (!empty($res)) {
         return $res[0];
     }
     return false;
 }
Example #9
0
 public static function findOneByColumn($column, $value)
 {
     $class = get_called_class();
     $db = new DB();
     $db->setClassName($class);
     $sql = 'SELECT * FROM ' . static::getTable() . ' WHERE ' . $column . '=:value';
     $res = $db->query($sql, [':value' => $value]);
     if (empty($res)) {
         throw new ModelException('Ничего не найдено...');
     }
     return $res[0];
 }
 public static function findAll()
 {
     $class = get_called_class();
     $sql = 'SELECT * FORM ' . static::$table . ' ORDER BY date DESC';
     $db = new DB();
     $db->setClassName($class);
     $res = $db->query($sql);
     if (empty($res)) {
         throw new E404Exception('Не были извлечены данные из базы');
     }
     return $res;
 }
Example #11
0
 public static function findOneByColumn($column, $value)
 {
     $db = new DB();
     $db->setClassName(get_called_class());
     $sql = 'SELECT * FROM ' . static::$table . ' WHERE' . $column . '=:value';
     $res = $db->query($sql, [':value' => $value]);
     if (empty($res)) {
         throw new ModelException('Record not found... :(');
     }
     if (!empty($res)) {
         return $res[0];
     }
     return false;
 }
Example #12
0
 public function findByColumn($column, $value)
 {
     $db = new DB();
     $db->setClassName(get_called_class());
     return $db->query('SELECT * FROM ' . static::$table . ' WHERE ' . $column . ' LIKE ' . ':column', [':column' => '%' . $value . '%']);
 }