Birisi bana bu kurulum ile neyin yanlış gittiğini görmek için yardımcı olabilir
I build the @sql query in the function below like this. The extra quotes are setup in the conditions array.
$sql .= " WHERE $field = \"$value\"";
Pdo güncelleme fonksiyonu böyle şartlar dizi döngüler.
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.
Ben yapabilirim başka bir şey var mı?
Birisi bana bu konuda bazı girdi verebilir misiniz.
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 );
teşekkürler, Richard