PHP / SQL连接脚本[关闭]

someone please help me to set mysql database connection variable on below php scripts but I couldn't fixed it.

$sql = "SELECT DISTINCT r.itemID, r2.ratingValue - r.ratingValue 
            as rating_difference
            FROM rating r, rating r2
            WHERE r.userID=$userID AND 
                    r2.itemID=$itemID AND 
                    r2.userID=$userID;";
$db_result = mysql_query($sql, $connection);
$num_rows = mysql_num_rows($db_result);
while ($row = mysql_fetch_assoc($db_result)) {
    $other_itemID = $row["itemID"];
    $rating_difference = $row["rating_difference"];
    if (mysql_num_rows(mysql_query("SELECT itemID1 
    FROM dev WHERE itemID1=$itemID AND itemID2=$other_itemID",
    $connection)) > 0)  {
        $sql = "UPDATE dev SET count=count+1, 
    sum=sum+$rating_difference WHERE itemID1=$itemID 
    AND itemID2=$other_itemID";
        mysql_query($sql, $connection);
        if ($itemID != $other_itemID) {
            $sql = "UPDATE dev SET count=count+1, 
        sum=sum-$rating_difference 
        WHERE (itemID1=$other_itemID AND itemID2=$itemID)";
            mysql_query($sql, $connection);
        }
    }

You didn't connect to any database use some thing like this

$link = mysql_connect('dbhost', 'dbusername', 'dbpassword');
$connection = mysql_select_db('tablename', $link);