我有注册类,在这里我定义了公共函数insert并在bindParam
函数行中我收到错误消息:
致命错误:未捕获错误:只能通过引用传递变量
public function insert ( $table, $coloumns, $values, string $where = null, string $whereValue = null )
{
global $db;
$tbl_columns = array();
foreach ($coloumns as $key => $value) {
$tbl_columns[] = ":{$value}";
}
$tbl_columns = implode(', ', $tbl_columns);
$values = implode(',', $values);
$coloumns2 = implode(',', $coloumns);
$sql = " INSERT INTO $table ( $coloumns2 ) VALUES ( $tbl_columns )";
if($where && $whereValue) {
$sql .= " WHERE $where = '$whereValue' ";
}
$stm = $db->prepare($sql);
foreach ($coloumns as $key => $value) {
$stm->bindParam(":{$value}", $values[$key]);
}
return $sql;
}