Пример #1
0
 public function __construct($start, $type, $col, $operator, $val, $escape)
 {
     $this->start = $start;
     if ($val === null) {
         $val = $operator;
         $operator = '=';
     }
     $op = ['=', '<', '<=', '>', '>=', '!=', 'LIKE', 'IN', 'NOT IN'];
     $op_no_quote = ['LIKE', 'IN', 'NOT IN'];
     if (!in_array($operator, $op)) {
         $operator = '=';
     }
     if ($escape && !in_array($operator, $op_no_quote) && is_string($val)) {
         $val = Database::get()->quote($val);
     }
     if ($operator == 'IN' || $operator == 'NOT IN') {
         $val = $this->in($val);
     }
     if ($operator == 'LIKE') {
         $val = "'{$val}'";
     }
     $this->type = $type;
     $this->col = $col;
     $this->op = $operator;
     $this->val = $val;
 }
Пример #2
0
 private function saveInsert($query)
 {
     $keys = [];
     foreach ($this->desc as $k => $v) {
         $val = $this->{$k};
         switch ($v) {
             case \PDO::PARAM_INT:
             case \PDO::PARAM_BOOL:
                 $keys[$k] = $val;
                 break;
             case \PDO::PARAM_STR:
                 $keys[$k] = Database::get()->quote($val);
                 break;
             default:
                 break;
         }
     }
     $query = $query->columns(array_keys($keys));
     return $query->values($keys)->save();
 }
Пример #3
0
 public function save()
 {
     $first = reset($this->table);
     $query = $first['table'] . ' ';
     switch ($this->type) {
         case Statement::TYPE_INSERT:
             $query = 'INSERT INTO ' . $query;
             $query .= $this->insertSQL();
             break;
         case Statement::TYPE_UPDATE:
             $query = 'UPDATE ' . $query;
             $query .= $this->updateSQL();
             break;
         case Statement::TYPE_DELETE:
             $query = 'DELETE FROM ' . $query;
             $query .= $this->deleteSQL();
             break;
     }
     $req = Database::get()->prepare($query);
     return $req->execute();
 }