php - Why the PDO statement error comes in this code? -
i have following code, unable figure out why pdo statement error occurs, here code
try { $db = new pdo("mysql:dbname=imdb","username","pwd"); $db->setattribute(pdo::attr_errmode, pdo::errmode_exception); $first_name=$db->quote($first_name); $last_name=$db->quote($last_name); $row_id=$db->query("select id actors last_name=$last_name , first_name ${first_name} order film_count desc limit 1"); if ($row_id->rowcount() > 0) { $idrow=$row_id->fetch_assoc(); print_r($idrow); return $row_id; } else { return null; } } catch (pdoexception $ex) { ?> <p>sorry, database error occurred. please try again later.</p> <p>(error details: <?= $ex->getmessage() ?>)</p> <?php return null; }
i error when run
fatal error: call undefined method pdostatement::fetch_assoc()
any help?
because error says. fetch_assoc()
isn't defined.
you want
$row_id->fetch(pdo::fetch_assoc)
fetch()
correct method name , pass 1 of pdo constants determine type of variable back.
Comments
Post a Comment