i trying print results of query, reason following error: fatal error: call member function fetch() on boolean in h:\some-location\ on line x
this code:
<?php $query = "select adid given touser = :userid"; $query_params = array( ':userid' => $_session['user']['id'] ); try { $stmt = $db->prepare($query); $result = $stmt->execute($query_params); } catch(pdoexception $ex) { echo "failed run query: " . $ex->getmessage(); } while ($row = $result->fetch(pdo::fetch_assoc)) { echo $row['adid']; } ?> what's wrong?
as docs , error show, execute returns boolean: http://php.net/manual/en/pdostatement.execute.php
you need call fetch() on statement, not return value of execute. : http://php.net/manual/en/pdostatement.fetch.php
so replace $result>fetch() $stmt->fetch().
Comments
Post a Comment