我如何将bindingValues与数组名PDO PHP [重复]

问题描述 投票:-1回答:1
[我收到错误消息:“警告:PDOStatement :: execute():SQLSTATE [HY093]:无效的参数号:在行----中混合了命名和位置参数,当我试图将它们全部放入数组中时”。

但是我不知道该怎么做。为了使bindValues与数组一起工作,我在尝试时不断出错。

$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));

感谢您的时间和回答。
php pdo
1个回答
-1
投票
您已经在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();

© www.soinside.com 2019 - 2024. All rights reserved.