wow
nothing
This commit is contained in:
parent
d40198ab95
commit
0b8cbe457c
2 changed files with 22 additions and 5 deletions
|
@ -3,20 +3,37 @@ namespace AroMVC\Database;
|
|||
|
||||
class Insertable extends Queryable {
|
||||
protected $table = null;
|
||||
protected $fields = [];
|
||||
|
||||
public function __construct(string $table) {
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
public function value(string $name, $value): Insertable {
|
||||
$fields[$name] = $value;
|
||||
$this->params[$name] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function values(array $values): Insertable {
|
||||
foreach($values as $name => $value)
|
||||
$fields[$name] = $value;
|
||||
$this->params = array_merge($this->params, $values);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function clear(): Insertable {
|
||||
$this->params = [];
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
$fields = "(". implode(", ", array_map(function($val) {
|
||||
return "`$val`";
|
||||
}, array_keys($this->params))) .")";
|
||||
|
||||
$values = "(". implode(", ", array_map(function($val) {
|
||||
return ":$val";
|
||||
}, array_values($this->params))) .")";
|
||||
|
||||
$this->query = implode(" ", ["INSERT INTO `$this->table`", $fields, "VALUES", $values]);
|
||||
parent::execute();
|
||||
return $this;
|
||||
}
|
||||
}
|
Reference in a new issue