Closed elcarim closed 2 years ago
UPDATE user SET user_points = user_points + 10 WHERE user_id = 123
$db-> table( 'user' )->where( 'user_id', 123 ) -> update ( ['user_points' => ['+ 10']] )
public function update(array $data, $type = false)
{
$query = 'UPDATE ' . $this->from . ' SET ';
$values = [];
foreach ($data as $column => $val) {
if (is_array($val))
$values[] = $column . '=' . $column . ' '. $val[0];
else
$values[] = $column . '=' . $this->escape($val);
}
$query .= implode(',', $values);
if (!is_null($this->where)) {
$query .= ' WHERE ' . $this->where;
}
if (!is_null($this->orderBy)) {
$query .= ' ORDER BY ' . $this->orderBy;
}
if (!is_null($this->limit)) {
$query .= ' LIMIT ' . $this->limit;
}
return $type === true ? $query : $this->query($query, false);
}
Hi @elcarim
Nice solution. But I've been working on a new version which has new capabilities that solve problems like that. It will release it in next weeks but I can't say exact date right now. Until to new version, you can create a new class that extend Pdox and override the update
method to use your solution.
Thanks.
thanks for pdox. it is amazing! putin-huylo!
question! UPDATE user SET user_points = user_points + 1 WHERE user_id = 123 thx