/** * Save model. * * @return bool */ public function save() { $keys = array_keys($this->attributesValues); $preparedKeysString = implode(',', $keys); $preparedKeysBind = str_replace(',', ',:', ':' . $preparedKeysString); try { $query = $this->db->prepare('INSERT INTO ' . $this->table . ' (' . $preparedKeysString . ') VALUES (' . $preparedKeysBind . ')'); $query->execute($this->attributesValues); } catch (\Exception $e) { Router::ErrorResponse('Invalid request'); die; } return $this->db->lastInsertId(); }