如何将bindingValues与数组名结合到PDO PHP中
我收到一个错误“警告:PDOStatement::execute():SQLSTATE[HY093]:无效参数编号:行中混合了命名参数和位置参数----当我试图将其全部放入数组时” 但我不知道我如何才能做到这一点。为了让bindingValues与数组一起工作,我在尝试时不断出错如何将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
$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组合