我想尝试使用bindParam来显示数据库中的数据,但是我得到了一些错误。
可恢复的致命错误:PDOStatement类的对象无法在第15行的C:\xampp\htdocs\piratefiles\search.php中转换为字符串
这是我的密码

$category = htmlentities($_GET['c']);
$query = htmlentities($_GET['q']);

$page = (isset($_GET['page'])) ? $_GET['page'] : 1;
$limit = 20;
$limit_start = ($page - 1) * $limit;

$query = $db->prepare ("SELECT * FROM `posting` WHERE 'category' = :category AND 'file_name' like :query ORDER BY date DESC LIMIT ".$limit_start.",".$limit);

$query->bindParam(":category", $category);
$query->bindParam(":query", $query);

$query->execute();

最佳答案

$query是用户输入,然后将其指定为PDOStatement,然后将其传递回bindParam
更改变量名。

$category = htmlentities($_GET['c']);
$query = htmlentities($_GET['q']);

$page = (isset($_GET['page'])) ? $_GET['page'] : 1;
$limit = 20;
$limit_start = ($page - 1) * $limit;

$stmt = $db->prepare ("SELECT * FROM `posting` WHERE 'category' = :category AND 'file_name' like :query ORDER BY date DESC LIMIT ".$limit_start.",".$limit);

$stmt->bindParam(":category", $category);
$stmt->bindParam(":query", $query);

$stmt->execute();

关于php - 使用bindParam显示数据库中的数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48039431/

10-13 06:44
查看更多