Search code examples
doctrinedbal

Doctrine DBAL increment


how can I increment a value?

$app->db->update('videos', array(
    'views' => 'views + 1'
), array(
    'id' => $id
));

It doesn't work in many ways I tried.


Solution

  • A better approach could be to use the method executeUpdate()

    $app->db->executeUpdate("UPDATE videos SET views=views+1 WHERE id=?", array($id));
    

    Edit 2022

    The API is working but marked deprecated. Use executeStatement() instead of executeUpdate()