我正在为 MySQLi 编写一个包装类。在那里,我正在编写一个函数来接受可以调用的查询和可变数量的参数mysqli_stmt::bind_param
。这是代码:
<?php
class DbHelper {
....
public function Execute($query, $params){
$this->open(); # Opens a connection to the database using MySQLi API
$stmt = $this->mysqli->prepare($query);
try{
$result = call_user_func_array(array($stmt, 'bind_param'), $params);
}
catch(Exception $ex){
# Handle Exception
}
}
....
}
?>
这是我调用该函数的方式:
<?php
$db = new DbHelper();
$params = array('i', $stateID);
$result = $db->Execute('SELECT * FROM mst_cities WHERE State_ID = ?', $params);
?>
当我运行代码时,我收到如下警告:
Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given in......
我应该怎么办?