Search MYSQL with PHP and JSON

Asked

Viewed 45 times

1

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

and would like to display all lines containing the 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

  • Need to debug, see if the problem is in the code or if the query returned any error

  • Related: https://answall.com/a/376919/45810 although this question presented an error not related to a query-specific problem, but rather that it was applying a method in one value boolean (true or false), instead of the object PDOStatement, as the documentation suggests.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.