0

I have UPDATE posts SET viewed = viewed + 1 WHERE id = 1 MySql Query

I have referred https://webkul.com/blog/magento2-write-custom-mysql-query-without-using-model/ But i want to as we do Select Way, Means Standard Way

Example:

$select = $this->getConnection()
                ->select()
                ->from(['posts' => $this->getMainTable()])
                ->where(
                'posts.id = ?', $id);

1 Answer 1

3

Try using:

$this->getConnection()->update(
    'posts',
    [
        'viewed' => new \Zend_Db_Expr('viewed + 1'),
    ],
    ["id = ?" => 1]
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.