for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Wandu\Database\Query;
use Wandu\Database\Contracts\QueryInterface;
use Wandu\Database\Query\Expression\HasWhereExpression;
use Wandu\Database\Support\Helper;
class UpdateQuery extends HasWhereExpression implements QueryInterface
{
/** @var string */
protected $table;
/** @var array */
protected $attributes;
/**
* @param string $table
* @param array $attributes
*/
public function __construct($table, array $attributes = [])
$this->table = $table;
$this->attributes = $attributes;
}
* @return static
public function set(array $attributes = [])
return $this;
public function addSet(array $attributes = [])
$this->attributes = array_merge($this->attributes, $attributes);
* {@inheritdoc}
public function toSql()
$parts = ['UPDATE `' . $this->table . '`'];
if (count($this->attributes)) {
$columns = array_keys($this->attributes);
$parts[] = "SET " . Helper::arrayImplode(', ', $columns, "`", "` = ?");
if ($part = parent::toSql()) {
$parts[] = $part;
return implode(' ', $parts);
public function getBindings()
return array_merge(array_values($this->attributes), parent::getBindings());