0

As stated in the title, how do I update the field by adding +1?

I'm using a PDO wrapper class from http://www.imavex.com/php-pdo-wrapper-class/index.php

I tried the code below and it's not updating the field:

1. $update = array('log' => 'log+1');
2. $update = array('log' => '+1');

$DB->update('user', $update, "idClient = 1");

Please help!

jasonlam604
  • 1,456
  • 2
  • 16
  • 25
tonoslfx
  • 3,422
  • 15
  • 65
  • 107

2 Answers2

2

This is the query you are ultimately shooting for:

"UPDATE user SET log = log + 1 WHERE idClient = 1";

With that PDO syntax, I am assuming it would look something like:

$update = array('log' => 'log +1');
$DB->update('user', $update, 'idClient = 1');

Edit:

The errors need to be logged, check this out: https://stackoverflow.com/a/2413308/185672

Community
  • 1
  • 1
Phil
  • 10,948
  • 17
  • 69
  • 101
0

You can also try this way and it is safe as well

$sql = 'UPDATE user SET log = log + 1 WHERE ( idClient = :userid )';
$prepStatement = $pdo->prepare( $sql );
$prepStatement->execute(array(':userid' => 1));
GBD
  • 15,847
  • 2
  • 46
  • 50