我需要动态生成需要从PHP在Postgresql中更新的列名。这是代码和错误:
$Col = "dog_".$Num."_pic"; $query_params = array( ':user_id_' => $CustomerID, 'dog_path' => $filePath, 'dog_col' => $Col) ; $sql = "UPDATE users SET `:dog_col`=:dog_path WHERE `username`=:user_id_";
我也尝试过pg_escape_string()使用该字符串。
pg_escape_string()
这是错误。
"SQLSTATE[42S22]: Column not found: 1054 Unknown column ''dog_1_pic'' in 'field list'"}
您不能在查询中绑定列名称:
$sql = "UPDATE users SET `:dog_col`=:dog_path WHERE `username`=:user_id_";
在这种情况下,您必须使用如下变量:
$column = 'myColumn'; $sql = "UPDATE users SET $column = :dog_path WHERE username = :user_id_";