Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.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
如何将bindingValues与数组名结合到PDO PHP中_Php_Pdo - Fatal编程技术网

如何将bindingValues与数组名结合到PDO PHP中

如何将bindingValues与数组名结合到PDO PHP中,php,pdo,Php,Pdo,我收到一个错误“警告:PDOStatement::execute():SQLSTATE[HY093]:无效参数编号:行中混合了命名参数和位置参数----当我试图将其全部放入数组时” 但我不知道我如何才能做到这一点。为了让bindingValues与数组一起工作,我在尝试时不断出错 $text = htmlspecialchars($text); // prepare the mysql query to select the users $get_product = $c

我收到一个错误“警告:PDOStatement::execute():SQLSTATE[HY093]:无效参数编号:行中混合了命名参数和位置参数----当我试图将其全部放入数组时”

但我不知道我如何才能做到这一点。为了让bindingValues与数组一起工作,我在尝试时不断出错

    $text = htmlspecialchars($text);
    // prepare the mysql query to select the users
    $get_product = $connect->prepare("SELECT name FROM products WHERE name LIKE concat('%', :name, '%')  ORDER BY created DESC LIMIT ?, ? ");

    $get_product->bindValue(1, $from_record_numLiveSearch, PDO::PARAM_INT);
    $get_product->bindValue(2, $records_per_pageLiveSearch, PDO::PARAM_INT);

    // execute the query
    $get_product -> execute(array('name' => $text));

感谢您的时间和回答。

您已经在bindValue中添加了参数值,因此不需要传递数组来执行函数,要解决您的问题,请尝试以下操作:

//$text = htmlspecialchars($text);

$get_product = $connect->prepare("SELECT name FROM 
 products ORDER BY created DESC LIMIT ?, ? ");
$get_product->bindValue(1, 
$from_record_numLiveSearch, PDO::PARAM_INT);
$get_product->bindValue(2, 
$records_per_pageLiveSearch, PDO::PARAM_INT);
$get_product->execute();

1) 不能混合使用数字参数和命名参数。2) 我很确定不能将
bindParam
/
bindValue
execute()
数组混合使用。3) 您的查询中没有
name
参数如何使其工作——因为您需要
PDO::PARAM_INT
键入
LIMIT
params,请坚持使用
bindParam
/
bindValue
并仅使用一种参数格式;姓名或位置谢谢你的回答。这是我第一次合并它,所以我想知道它是如何工作的。我忘记在查询中发布:NAME值。我用正确的问题编辑了我的问题。我把问题贴错了。查询还有
其中的名称,如concat(“%”,:name,“%”)
。如何将数组“name”与bindValue组合