From 0b8cbe457c3b55598f99d6cfe0325df0da415a23 Mon Sep 17 00:00:00 2001 From: Malloc of Kuzkycyziklistan Date: Tue, 7 Mar 2017 16:00:14 -0600 Subject: [PATCH] wow nothing --- AroMVC/Database/Insertable.php | 25 +++++++++++++++++++++---- AroMVC/Database/Modifiable.php | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/AroMVC/Database/Insertable.php b/AroMVC/Database/Insertable.php index 3e81634..1e0ef0b 100644 --- a/AroMVC/Database/Insertable.php +++ b/AroMVC/Database/Insertable.php @@ -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; } } \ No newline at end of file diff --git a/AroMVC/Database/Modifiable.php b/AroMVC/Database/Modifiable.php index 8f57e49..53bafa6 100644 --- a/AroMVC/Database/Modifiable.php +++ b/AroMVC/Database/Modifiable.php @@ -2,5 +2,5 @@ namespace AroMVC\Database; class Modifiable extends Queryable { - + } \ No newline at end of file