**
(!)警告:PDOStatement :: execute():SQLSTATE [HY093]:无效 参数编号:绑定变量的数量与 令牌
**
我正在尝试建立一个类来动态更新数据库,但出现此错误:难以理解,因为参数确实匹配。 关键点:在localhost上,我得到了错误,但未执行代码,但是在实时服务器上,虽然执行了代码,但仍然收到500内部服务器错误。拜托,我怎么了?还是更好的主意?
1。这是我的$ DATA
$ redirectTo =“ https://helpme.com”;
$data = ['loanamount' => $loanamount,
'term' => $terms,
'interest' => $interest,
'repayment' => $totalrepayment,
'monthly_repayment=?' => $monthlyrepayment,
'id' => $id];
2。这是我的课程
public function updateMultiple($data, $dbtable, $identifier,
$identifier_ans, $redirectTo)
{try{ $implodeKey = implode('=?, ', array_keys($data));
$implodeKey = rtrim($implodeKey, ', id');
$implodeValue = implode(', ', array_values($data));
$sql = "UPDATE $dbtable SET $implodeKey WHERE $identifier =?";
$stmt = $this->connect()->prepare($sql);
$result = $stmt->execute([$implodeValue]);
if($result){$redirectTo;}}
catch (PDOException $e){echo $e->getMessage(), PHP_EOL;} }
我通过使用EXPLODE()将$ implodeValue转换回数组来解决了这个问题
public function updateMultiple(array $data, $dbtable, $identifier,
int $identifier_ans)
{$implodeKey = implode('=?, ', array_keys($data));
$implodeKey = rtrim($implodeKey, ', id');
$implodeValue = array_values($data);
$implodeValue = implode(', ', $implodeValue);
$implodeValue = explode(" " , $implodeValue);
$sql = "UPDATE $dbtable SET $implodeKey WHERE $identifier =?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute($implodeValue);
3。实例化并实现该类
$insert_db = new Insert();
$insert_db->updateMultiple($data, 'helpme', 'help', $id, $redirectTo);
$sql(var_dump) = 'UPDATE showal_old SET loanamount=?, term=?, interest=?,
repayment=?, monthly_repayment=? WHERE id =?'
$implodeValue(print_r) `440000, 1, 44000, 484000, 484000, 13964`