我想準備一個未知數量的參數的SQL語句!這些參數在數組中已經過去了。該函數的語法正常會是:傳遞數組作爲參數在PHP
$stmt->bind_param("string of types",param1,param2,...,paramN)
問題是我不知道如何在功能$ stmt-> bind_param參數添加了一個數組
我有這樣的代碼,但它不工作:
$stmt= $conn->prepare($request['query']);
if(isset($request['params'])){
call_user_func_array('$stmt->bind_param',$request['params']);
}
$stmt->execute();
$result = $stmt->get_result();
$ request ['params']包含需要在函數中添加的正確參數。
但call_user_func_array給了我這個錯誤:
call_user_func_array() expects parameter 1 to be a valid callback, function '$stmt->bind_param' not found or invalid function.
我想call_user_func_array可能不使用正確的功能! 我搜索了幾個小時,但找不到解決這個小問題的方法。
請閱讀[文檔](http://php.net/call_user_func_array)關於您正在使用的功能。請注意,這些示例顯示瞭如何通過此函數正確調用對象方法。 –