Hello,
Can someone help me to see what is going wrong with this setup
I build the @sql query in the function below like this. The extra quotes are setup in the conditions array.
$sql .= " WHERE $field = \"$value\"";
The pdo update function loops the conditions array like this.
if (!is_null($conditions))
{
$cond = ' WHERE';
$obj = new CachingIterator(new ArrayIterator($conditions));
foreach($obj as $k=>$v)
{
$cond .= " $k=$v";
$cond .= $obj->hasNext() ? ' AND' : '';
}
}
My point to make is that I can not build arrays with values without adding slashes for quotation marks around the values. Otherwise the sql error that is being thrown is that it is an unknown column.
Is there something other that I can do?
Could someone give me some input on this please.
edit: the rest off the update function
Where could I bind the values of the conditions array and have them executed also? As I am seeing it now, only the values array is executed? Do I need to loop both arrays and then merge both arrays?
$obj = new CachingIterator(new ArrayIterator($values));
$db = db::getInstance();
$sql = "UPDATE $table SET \n";
foreach( $obj as $field=>$val)
{
$sql .= "$field= :$field";
$sql .= $obj->hasNext() ? ',' : '';
$sql .= "\n";
}
$sql .= $cond ;
$stmt = $db->prepare($sql);
// bind de params
foreach($values as $k=>$v)
{
$stmt->bindParam(':'.$k, $v);
}
$stmt->execute($values );
thanks, Richard