Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.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将_param绑定到相等的数组,但只有一个工作_Php_Arrays_Binding_Prepared Statement - Fatal编程技术网

PHP将_param绑定到相等的数组,但只有一个工作

PHP将_param绑定到相等的数组,但只有一个工作,php,arrays,binding,prepared-statement,Php,Arrays,Binding,Prepared Statement,我跟踪了很多论坛记录。 我有两种不同的方法来构建绑定数组,但是为什么第一种方法不起作用呢 <?php class BindParam{ private $values = array(), $types = ''; public function add( $type, &$value ){ $this->values[] = $value; $this->types .= $type; } public function get(){

我跟踪了很多论坛记录。 我有两种不同的方法来构建绑定数组,但是为什么第一种方法不起作用呢

<?php
class BindParam{ 
private $values = array(), $types = ''; 

public function add( $type, &$value ){ 
    $this->values[] = $value; 
    $this->types .= $type; 
} 

public function get(){ 
    return array_merge(array($this->types), $this->values); 
} 
} 
class db
{
....

$stmt = $conn->prepare(@"SELECT xy FROM xx WHERE yy = ? AND zz = ?");

$bindParam = new BindParam(); 

$typ ="";
$par;

for( $i = 0; $i < count($params); $i++)
{
    $bindParam->add($params[$i][0], $params[$i][1]);//for example 1
    $typ .= $params[$i][0];//for example 2
    $par[] = $params[$i][1];//for example 2
}
echo "Example1: ";
print_r($bindParam->get());

echo "<br>Example2: ";
$bind_names[] = $typ;
for ($i=0; $i<count($par);$i++) 
{
    $bind_name = 'bind' . $i;
    $$bind_name = $par[$i];
    $bind_names[] = &$$bind_name;
}

print_r($bind_names);


$return = call_user_func_array(array($stmt,'bind_param'),$bind_names);
//$return = call_user_func_array(array($stmt,'bind_param'),$bindParam->get());
echo "<br>Binding return: ".$return;

.
.
.
}
例如,输出为1:

示例1:Array[0]=>ss[1]=>test[2]=>test 示例2:Array[0]=>ss[1]=>test[2]=>test 绑定返回:1

例如,输出为2:

示例1:Array[0]=>ss[1]=>test[2]=>test 示例2:Array[0]=>ss[1]=>test[2]=>test 警告:mysqli_stmt::bind_param的参数2应为引用,值在。。。 绑定返回:


注释掉的代码/$return=example2 dosent起作用。

什么是count$params?对不起,这是一个数组和类db的一个参数函数获取一个查询字符串和一个参数数组:$params=array array,bb,array,pw;输出为:数组[0]=>Array[0]=>s[1]=>test[1]=>Array[0]=>s[1]=>testalternative我可以使用$typ.=substrstrtolowergettype$params[$i][1],0,1;而且不需要多数组,但认为它更好,因为参数列表使用“bindValue”比使用“bindParam”更可靠,因为任何值,即使是计算值也可以与“bindValue”一起使用。i、 e.除非必须,否则不要使用“bindParam”,这是一个有用的指导原则。