PDO prepare statement and match against in boolean mode

后端 未结 1 1722
臣服心动
臣服心动 2020-12-18 13:33

If I run this simple query from the console by directly typing

 SELECT COUNT(*) AS total FROM articles WHERE MATCH(title) AGAINST (\'+php +mysql\' IN BOOLEAN         


        
相关标签:
1条回答
  • 2020-12-18 13:52

    You should simply create a statement like this:

    $query = 'SELECT COUNT(*) AS total FROM articles WHERE MATCH(title) AGAINST (:query IN BOOLEAN MODE)';
    $stmt = $pdo->prepare($query);
    

    And then bind the params:

    $keywords = ['php', 'mysql'];
    $against = '';
    for($i = 0; $i < count($keywords); $i++){
        $against .= ' +' . $keywords[$i];   
    }
    $stmt->execute(array(
        ':query' => $against
    ));
    
    0 讨论(0)
提交回复
热议问题