public function processInsert(DatabaseLayer\Insert $thing) { // SELECTORS if (count($thing->getTables()) > 1) { throw new Exception("Active Record Cannot insert into more than one table at a time!"); } $tables = $thing->getTables(); $table = end($tables); $data = $thing->getData(); $keys = []; $values = []; foreach ($data as $key => $value) { $key = trim($key, "`"); if (is_object($value) || is_array($value)) { $value = JsonPrettyPrinter::Json($value); } $keys[] = $key; $value_slashed = str_replace("'", "''", $value); if ($value === null) { $value = "NULL"; } elseif (is_numeric($value)) { // Do nothing } else { $value = "'{$value_slashed}'"; } $values[] = $value; } $selector = "INSERT INTO {$table->getName()} "; $columns = "(`" . implode("`, `", $keys) . "`)"; $values = "(" . implode(", ", $values) . ")"; $query = "{$selector}\n{$columns} \nVALUES \n{$values}"; // echo "*** Just before query(): ".$thing->getModel() . "\n"; $this->query($query, $thing->getModel()); $insertId = $this->lastInsertId(); return $insertId; }