I have a database class that uses PDO and it all works until i need to do an update where I increment the value
What I have is a table and one of the columns is called 'counter' and I need to update this table every time a page is visited
This is the function that handles all the PDO and creates the query
/**
* update
* @param string $table A name of table to insert into
* @param string $data An associative array
* @param string $where the WHERE query part
*/
public function update($table, $data, $where)
{
ksort($data);
$fieldDetails = NULL;
foreach($data as $key=> $value) {
$fieldDetails .= "`$key`=:$key,";
}
$fieldDetails = rtrim($fieldDetails, ',');
$sth = $this->prepare("UPDATE $table SET $fieldDetails WHERE $where");
foreach ($data as $key => $value) {
$sth->bindValue(":$key", $value);
}
$sth->execute();
}
and this is how I call the function by passing parametres to the function
$board = ucwords(str_replace('-',' ',$board));
$sql = "SELECT boardid from boards WHERE boardname = :board";
$rows = $this->db->select($sql, array(':board' => $board));
$postData = array(
'counter' => 'counter+1',
);
$this->db->update('topics', $postData, "`topicid` = {$topic} AND `boardid` = {$rows[0]['boardid']}");
It fails the update with this error message
The counter column is of type INT