我有以下代码,我无法弄清楚为什么会发生 PDO 语句错误,这是我的代码
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 FROM actors WHERE last_name=$last_name AND first_name LIKE ${first_name} ORDER BY 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, a database error occurred. Please try again later.</p>
<p>(Error details: <?= $ex->getMessage() ?>)</p>
<?php
return NULL;
}
运行时出现此错误
致命错误:调用未定义的方法 PDOStatement::fetch_assoc()
有什么帮助吗?