Search MYSQL with PHP and JSON

1

I have a table in the mysql database that has a genre field with this value:
[{"id": 2, "genre_name": "action"}, {"id": 1, "genre_name": "comedy"}]

and would like to display all rows containing genre_name with the value comedy

My code:

function genres(){
    $genres = $this->pdo->connect()->query("SELECT * FROM movie WHERE JSON_SEARCH(genre, 'comedy', '$.genre_name') IS NOT NULL");
    return $genres->fetchAll(PDO::FETCH_OBJ);
}

When I try to display the return of the values this error is displayed:

  

Fatal error: Uncaught Error: Call to a member function fetchAll () on   boolean in C: \ wamp64 \ www \ class \ contents.php on line 322

     

Error: Call to a member function fetchAll () on boolean in   C: \ wamp64 \ www \ class \ contents.php on line 322

    
asked by anonymous 17.11.2017 / 18:40

0 answers