我正在尝试从数据库中获取数据,但遇到此错误。查询中没有错误,因为它在 mysql 中完美运行。
为什么我会收到此错误?
[client 127.0.0.1] PHP Warning: mysql_query() expects parameter 2 to be resource, boolean given in /var/www/imdb.php on line 35
[client 127.0.0.1] PHP Warning: mysql_error() expects parameter 1 to be resource, boolean given in /var/www/imdb.php on line 35
php代码:
function getdirector($director)
{
global $db;
$query = 'select name from peopledb where peopleid = '.$director;
$result = mysql_query($query,$db) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
extract($row);
return $name;
}
function getactor($actor)
{
$query = 'select name from peopledb where peopleid = '.$actor;
$result = mysql_query($query,$db) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
extract($row);
return $name;
}
function getmovietype($type)
{
$query = 'select movietype from movietype where movieid = '.$type;
$result = mysql_query($query,$db) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
extract($row);
return $movietype;
}
$db = mysql_connect('localhost','root','saw123') or die("Connection error");
$db = mysql_select_db("moviesite",$db) or die(myql_error($db));
$query = 'select moviename,releaseyear,director,actor,type from movie';
$result = mysql_query($query,$db) or die(mysql_error($db));
$table = <<<ENDHTML
<div style="text-align: center;" >
<h2>The Ultimate movie database</h2>
<table border='1' cellpadding='1' cellspacing='2'
style="width: 70%; margin-left: auto; margin-right: auto;">
<tr>
<th>Movie title</th>
<th>year of release </th>
<th>Movie director</th>
<th>Movie Actor</th>
<th>Movie type</th>
</tr>
ENDHTML;
while ($row = mysql_fetch_assoc($result))
{
extract($row);
$director1 = getdirector($director);
$actor1 = getactor($actor);
$movietype1 = getmovietype($type);
$table .= <<<ENDHTML
<tr>
<td>$moviename</td>
<td>$releaseyear</td>
<td>$director1</td>
<td>$actor1</td>
<td>$movietype1</td>
</tr>
ENDHTML;
}
$table .=<<<ENDHTML
</table>
</div>
ENDHTML;
echo $table;
?>
*更新 ::: 无论我在哪里使用 mysql_error() 函数,它都会显示错误。现在删除所有“$db”参数后,它就可以工作了。为什么 ?*