我尝试使用bind_params创建一种动态创建查询字符串的方法。我想我会使用call_user_func_array(),但是我得到致命错误的错误:在 C:\ xampp \ htdocs \中调用未定义的方法mysqli :: execute()应用\ MyVyn \ Utils \ utils \ php \ servConn.php 在线 22
function conn($sQuery, $sTypes=null, $aParams=null){
var_dump($sQuery);
var_dump($sTypes);
var_dump($aParams);
$sMessage = '';
$db = new mysqli('localhost','root','','myvyn') or die('unable to connect!');
if($db->connect_errno){
$message = $db->connect_error;
} else{
var_dump("1");
$stmt = $db->prepare($sQuery);
if($sTypes&&$aParams){
var_dump("2");
$bindParams[] = $sTypes;
foreach($aParams as $param){
$bindParams[] = $param;
}
var_dump($bindParams);
call_user_func_array(array($stmt, 'bind_param'), $bindParams);
}
$stmt->execute();
$oResult = $stmt->get_result();
while($rows = $oResult->fetch_assoc()){
$aRows[] = $rows;
//foreach($rows As $value){
//$aRows[] = $value;
//}
}
$oResult->free();
$db->close();
return $aRows;
}
}