我有一个功能可以做到这一点:
function registerUser($firstName, $lastName, $address, $postcode, $email, $password)
{
$params = array($firstName, $lastName, $address, $postcode, $email, $password);
$result = $this->db->bind("INSERT INTO Users VALUES (?, ?, ?, ?, ?, ?)", 'ssssss', $params);
}
它发送到我的数据库类,它执行以下操作:
public function bind($query, $type, $params)
{
$this->query = $query;
$stmt = $this->mysqli->prepare($this->query);
$stmt->bind_param($type, $param);
$stmt->execute;
}
问题是这行不通。
我希望做的是获取$params
列表并让它在 之后列出它们$type
,以便查询类似于:
$stmt->bind_param('ssssss', $firstName, $lastName, $address, $postcode, $email, $password);
但显然我的做法是错误的。
有没有办法使数组...按原样转换为要在bind_param
查询阶段打印出来的列表?