doujiao9866 2017-12-31 02:16
浏览 99
已采纳

使用bindParam显示数据库中的数据

i want to try to showing my data from database using bindParam but i get some error.

Recoverable fatal error: Object of class PDOStatement could not be converted to string in C:\xampp\htdocs\piratefiles\search.php on line 15

here my code

$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();
  • 写回答

2条回答 默认 最新

  • duanlin1933 2017-12-31 02:21
    关注

    $query was the user input, then you assigned it as the PDOStatement, then your the passing it back to bindParam

    Change the var name.

    $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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?