nothing
This commit is contained in:
Malloc of Kuzkycyziklistan 2017-03-07 16:00:14 -06:00
parent d40198ab95
commit 0b8cbe457c
2 changed files with 22 additions and 5 deletions

View file

@ -3,20 +3,37 @@ namespace AroMVC\Database;
class Insertable extends Queryable { class Insertable extends Queryable {
protected $table = null; protected $table = null;
protected $fields = [];
public function __construct(string $table) { public function __construct(string $table) {
$this->table = $table; $this->table = $table;
} }
public function value(string $name, $value): Insertable { public function value(string $name, $value): Insertable {
$fields[$name] = $value; $this->params[$name] = $value;
return $this; return $this;
} }
public function values(array $values): Insertable { public function values(array $values): Insertable {
foreach($values as $name => $value) $this->params = array_merge($this->params, $values);
$fields[$name] = $value; 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; return $this;
} }
} }