Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 有没有办法将数组绑定到mysqli prepare_Php_Mysql_Stored Procedures_Mysqli - Fatal编程技术网

Php 有没有办法将数组绑定到mysqli prepare

Php 有没有办法将数组绑定到mysqli prepare,php,mysql,stored-procedures,mysqli,Php,Mysql,Stored Procedures,Mysqli,我试图创建一个类,该类将使用任意数量的变量执行多个存储过程中的任意一个 我在使用php和mysqli 我的类枚举一个数组,并根据元素数(如果有的话)构造一个字符串 例如,给出类似以下内容的调用spTestLogin(?) 我现在需要使用如下方式绑定数组中的输入: $params=array_merge( array($this->paramTypes), $this->paramValues ); call_user_func_array(array($stmt,

我试图创建一个类,该类将使用任意数量的变量执行多个存储过程中的任意一个

我在使用php和mysqli

  • 我的类枚举一个数组,并根据元素数(如果有的话)构造一个字符串
  • 例如,给出类似以下内容的
    调用spTestLogin(?)
  • 我现在需要使用如下方式绑定数组中的输入:

    $params=array_merge(
        array($this->paramTypes), 
        $this->paramValues
    );
    call_user_func_array(array($stmt, 'bind_param'), $params);
    
    $stmt->bind_param($this->paramTypes,$this->paramValues)//参数值是我的数组

那么如果这行得通的话,我可以努力得到我的结果


任何想法

你必须这样做:

$params=array_merge(
    array($this->paramTypes), 
    $this->paramValues
);
call_user_func_array(array($stmt, 'bind_param'), $params);
假设
$this->paramTypes
mysqli_stmt::bind_param
所需格式的字符串-如果不是,则必须首先创建此
字符串
参数


我不知道在这种情况下,
out
inout
参数是否有效。

将接受数量可变的参数

假设
$this->paramTypes
也是一个数组,其中包含每个变量的正确类型字符(“i”、“d”、“s”、“b”)中的一个,则可以执行以下操作

$params = $this->paramValues;
array_unshift($params, implode($this->paramTypes));
call_user_func_array( array( $stmt, 'bind_param' ), $params);
实际上,您创建了一个通常传递给bind_param()的参数数组,然后使用
call_user_func_array()进行调用。

也许有更好的方法可以做到这一点

编辑:刚意识到我在写这篇文章时被打败了,我现在就把这个答案留在这里,以防感兴趣