for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Keep;
trait Statement
{
private $statement;
private $attributes = [];
public function create(string $table, array $attributes): self
$this->attributes = $attributes;
$this->statement = 'INSERT INTO `' . $table . '` (`';
$this->statement .= Tool::getAttributesKey($attributes);
$this->statement .= '`) VALUES (:';
$this->statement .= Tool::getAttributesValue($attributes) . ')';
return $this;
}
public function all(string $table): self
$this->statement = "SELECT * FROM `{$table}`";
public function select(string $table, array $columns): self
$this->statement = 'SELECT `' . Tool::columns($columns) . "` FROM `{$table}`";
public function update(string $table, array $attributes): self
$set = '';
$key = array_keys($attributes);
$pop = array_pop($key);
foreach ($attributes as $key => $value) {
$set .= ($key == $pop) ? '' : "`{$key}` = :{$key}, ";
$set .= "`{$pop}` = :{$pop}";
$this->statement = "UPDATE `{$table}` SET {$set}";
public function delete(string $table): self
$this->statement = "DELETE FROM `{$table}`";