我正在尝试使用MySQL。我今天早上安装了软件,但每当我尝试在服务器上查看MySQL页面时,我总会收到以下错误:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in /home/users/2014/21244429/public_html/IT Assignment 2B/cart.php on line 7
Access denied for user 'root'@'localhost' (using password: YES)
我该如何解决这个问题?我现在一直在寻找解决方案,但没有任何帮助。安装MySQL时,我确实设置了密码,当我进入安装程序时,在检查root权限时是否接受此密码。
以下是我要显示的代码:
<?php
session_start();
$page = 'index.php';
mysql_connect('localhost','root','password') or die(mysql_error());
mysql_select_db('cart') or die(mysql_error());
echo "Done!"
?>
答案 0 :(得分:0)
Like @Jay Blanchard said on comment don't use mysql as it deprecated and will be removed in future.
这是使用mysqli的基本设置:
$conn = mysqli_connect('localhost', 'myUsernameHereAndDontPutPlaceholderHere', 'myPasswordHereIfISetupAPassword', 'myDatabaseNameHereYesShouldBeMyDatabaseNameHere');
我不想给mysql示例,因为它不再推荐了。