問題描述
我正在嘗試創建一個類,該類將使用任意數量的變量執行多個存儲過程中的任何一個
I'm trying to make a class that will execute any one of a number of stored procedures with any amount of variables
我使用 php 和 mysqli
Im using php and mysqli
- 我的類枚舉一個數組并根據元素的數量構造一個字符串
- 例如給出這樣的
CALL spTestLogin(?,?)
我現在需要使用這樣的方法綁定數組的輸入:
- My class enumerates an array and constructs a string based on the number of elements if any
- giving something like this
CALL spTestLogin(?,?)
for example I now need to bind the input from my array using somethin like this:
$stmt->bind_param($this->paramTypes,$this->paramValues);//paramValues 是我的數組
$stmt->bind_param($this->paramTypes,$this->paramValues);//paramValues is my array
如果可行的話,我可以努力獲得結果
Then if that works I can work on getting my results
任何想法
推薦答案
你必須這樣做:
$params=array_merge(
array($this->paramTypes),
$this->paramValues
);
call_user_func_array(array($stmt, 'bind_param'), $params);
鑒于 $this->paramTypes
是 mysqli_stmt::bind_param
所需格式的字符串 - 如果不是,則必須創建此 字符串
參數優先.
given that $this->paramTypes
is a string in the format required by mysqli_stmt::bind_param
- if not, you have to create this string
parameter first.
我不知道 out
或 inout
參數在這種情況下是否有效.
I don't know if out
or inout
parameters do work in this case.
這篇關于有沒有辦法將數組綁定到 mysqli prepare的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!