Add to exisiting db values, rather than overwrite - PDO

Posted by sam on Stack Overflow See other posts from Stack Overflow or by sam
Published on 2013-06-29T16:17:01Z Indexed on 2013/06/29 16:21 UTC
Read the original article Hit count: 163

Filed under:
|
|

Im trying to add to existing decimal value in table, for which im using the sql below:

UPDATE Funds SET Funds = Funds + :funds WHERE id = :id

Im using a pdo class to handle my db calls, with the method below being used to update the db, but i couldnt figure out how to amend it to output the above query, any ideas ?

public function add_to_values($table, $info, $where, $bind="") {
    $fields = $this->filter($table, $info);
    $fieldSize = sizeof($fields);

    $sql = "UPDATE " . $table . " SET ";
    for($f = 0; $f < $fieldSize; ++$f) {
        if($f > 0)
            $sql .= ", ";
        $sql .= $fields[$f] . " = :update_" . $fields[$f]; 
    }
    $sql .= " WHERE " . $where . ";";

    $bind = $this->cleanup($bind);
    foreach($fields as $field)
        $bind[":update_$field"] = $info[$field];

    return $this->run($sql, $bind);
}

© Stack Overflow or respective owner

Related posts about php

Related posts about sql