[英]mysql_connect(): Access denied for user 'root'@'localhost'
For school I have to build and basic website using PHP and MySQL. 对于学校,我必须使用PHP和MySQL构建和基本的网站。 The websites function is to allow a user to register and then sign in and out.
网站功能是允许用户注册然后登录和注销。 To do this, since I have no prior knowledge of PHP I was trying to follow this tutorial .
为此,由于我没有PHP的先验知识,因此我尝试遵循本教程 。 I got sever space with godaddy and using MySQL I created the database called details_db.
我通过godaddy获得了足够的空间,并使用MySQL创建了一个名为details_db的数据库。 I created the files the tutorial told me and uploaded to the server.
我创建了教程告诉我的文件,并上传到服务器。 Now when I go onto the website I get these errors.
现在,当我进入网站时,我得到了这些错误。
Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: NO) in /home/pendrive34/public_html/dbconnect.php on line 12
警告:mysql_connect():在第12行的/home/pendrive34/public_html/dbconnect.php中,对用户'root'@'localhost'的访问被拒绝(使用密码:NO)
Warning: mysql_select_db(): Access denied for user ''@'localhost' (using password: NO) in /home/pendrive34/public_html/dbconnect.php on line 13
警告:mysql_select_db():在第13行的/home/pendrive34/public_html/dbconnect.php中,对用户“ @'localhost”的访问被拒绝(使用密码:NO)
Warning: mysql_select_db(): A link to the server could not be established in /home/pendrive34/public_html/dbconnect.php on line 13 Connection failed : Access denied for user ''@'localhost' (using password: NO)
警告:mysql_select_db():在第13行的/home/pendrive34/public_html/dbconnect.php中无法建立到服务器的链接连接失败:对用户``@'localhost'的访问被拒绝(使用密码:NO)
This is the code in the file deconnect.php 这是文件deconnect.php中的代码
<?php
// this will avoid mysql_connect() deprecation error.
error_reporting( ~E_DEPRECATED & ~E_NOTICE );
// but I strongly suggest you to use PDO or MySQLi.
define('DBHOST', 'localhost');
define('DBUSER', 'root');
define('DBPASS', '');
define('DBNAME', 'details_db');
$conn = mysql_connect(DBHOST,DBUSER,DBPASS);
$dbcon = mysql_select_db(DBNAME);
if ( !$conn ) {
die("Connection failed : " . mysql_error());
}
if ( !$dbcon ) {
die("Database Connection failed : " . mysql_error());
}
I've been trying to find the answer to the problem for a while but my limited knowledge is holding me back. 我一直在尝试寻找问题的答案,但是我有限的知识使我退缩。
You have to write mysql root users password to 您必须编写mysql root用户密码才能
define('DBPASS', '');
this line like.. 这条线像..
define('DBPASS', 'password_of_root_user');
If you are trying to connect a database on remote machine (like a shared hosting), you have to change DBHOST, DBUSER and DBPASS to values that given you by hosting company. 如果您尝试连接远程计算机上的数据库(例如共享托管),则必须将DBHOST,DBUSER和DBPASS更改为托管公司提供的值。
you need to provide the password in define('DBPASS', 'PASSWORD');
您需要在
define('DBPASS', 'PASSWORD');
提供密码define('DBPASS', 'PASSWORD');
if you are working on local machine the default password might be " root " 如果您在本地计算机上工作,则默认密码可能是“ root ”
define('DBPASS', 'root');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.