2

I'm working on a super-simple counter for my application. I am able to insert rows using '$date' and '$c' just fine, but updating does not work.

This works:

$c = 8;
$today = date('Y-m-d');
$insert_count = $db->prepare("INSERT INTO COUNTER (COUNTER.date, clicks) VALUES ('" . $today . "', ?)");
$insert_count->execute(array($c));

This does not

$c = 8;
$today = date('Y-m-d');
$update_count = $db->prepare("UPDATE COUNTER SET clicks = clicks + ? WHERE COUNTER.date = '" . $today . "'");
$update_count->execute(array($c));

No errors, nothing.

Yev
  • 2,051
  • 9
  • 27
  • 46

1 Answers1

0

I don't think the ? binding placeholder works with calculations. Have you tried using named binding parameters instead?

$update_count = $db->prepare("UPDATE COUNTER SET clicks = clicks + :increment WHERE COUNTER.date = '" . $today . "'");
$update_count->execute(array("increment"=>$c));

When you say there are no errors, there is no output for this command after execute?

print_r($db->errorInfo());
Brent Baisley
  • 12,641
  • 2
  • 26
  • 39