PHP / SQL连接脚本

时间:2014-10-15 12:03:53

标签: php mysql database

有人请帮我在下面的PHP脚本上设置mysql数据库连接变量,但我无法修复它。

$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);
        }
    }

1 个答案:

答案 0 :(得分:-1)

你没有连接任何数据库使用像这样的东西

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