用户'root'@'localhost'拒绝访问(使用密码:否)

时间:2012-06-14 14:23:14

标签: mysql sql

我在我的php页面中创建了一个简单的数据库连接,并且它正常工作,因为它在执行此操作时没有显示任何错误

<?php
    $link = mysql_connect('www.ccccccccccccc.co.uk', 'cccccccccc', 'accccc');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }

    /*echo 'Connected successfully';*/
    echo "DB : <font color='green'>ACTIVE</font>";

    mysql_close($link);
?>

The problem is the page is showing error Access denied for user 'root'@'localhost' (using password: NO) while executing 

<?php
    $q = mysql_query("SELECT slno, name, idno  FROM $memlist") or die(mysql_error());

    echo "<table><tr><th> NO</th><th> NAME</th>
            <th> ID NO</th></tr>";

    while($row = mysql_fetch_array($q)){
        extract($row);

        echo "<tr><td>$slno</td><td>$name</td>
            <td>$idno</td></tr>";
    }
    echo"</table>";
?>

我直接在本地主机上使用服务器

1 个答案:

答案 0 :(得分:6)

您似乎没有在第二段代码中连接到数据库,因此它尝试使用默认设置进行连接(由于安全问题,这显然无法正确)

至于第一段代码,你打开后立即关闭连接,这是毫无意义的。

相关问题