mysql_query()期望参数2是resource,boolean

I am trying to get data from the database but experiencing this error. There is no error in the query as it runs perfectly in mysql.

Why i am getting this error then ?

[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 code:

    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;


    ?>

*UPDATE ::: it was showing error wherever i was using mysql_error() function. Now after removing all the "$db" parameters, it just works. Why ?*

Just call it this way:

$result = mysql_query($query);

If you look at the mysql_connect function it returns false ( a boolean) on failure:

http://php.net/manual/en/function.mysql-connect.php

So your connection is likely not even established.

Edit: Look at this function: http://php.net/manual/en/function.mysql-select-db.php

You're calling:

$db = mysql_connect('localhost','root','saw123') or die("Connection error");
    $db = mysql_select_db("moviesite",$db) or die(myql_error($db));

The second line sets $db to either true or false - since mysql_select_db only ever returns a boolean.

Edit 2: What you likely meant was:

$db = mysql_connect('localhost','root','saw123') or die("Connection error");
mysql_select_db("moviesite",$db) or die(myql_error($db));

$db in this case would not be appropriately named; it'd be more accurately called $connection or $db_connection or something like that.