2
I’m trying to get one array
associative as argument of this methods, actually receives a array
in the first argument and a numerical value in the second.
My question is how to make the variable $id
do not repeat?
'Cause you’re making that mistake:
Warning: Pdostatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid Parameter number: number of bound variables does not match number of tokens in C: Program Files (x86) Easyphp-5.3.8.0 www connect standardModel.php on line 92
Source:
<?php
public function update($data = array(), $id)
{
if (is_array($data) && count($data) > 0 && $id != false)
{
$sql = "update `{$this->table}` set ";
foreach($data as $key => $value)
{
$sql .= $key . " = ?, ";
}
$sql = substr($sql, 0, - 2);
$sql .= "where id = ?";
$query = $this->db->prepare($sql);
foreach($data as $value)
{
$query->bindValue($value . ",",$id);
}
if ($query->execute()) {
return true;
} else {
return false;
}
}
}
?>
You can make a dynamic bind by passing the values in the execute http://answall.com/q/33524/91
– rray
The last lines (the whole
if
) can be simplified toreturn $query->execute();
. Don’t complicate what is simple.– Maniero