PHP登录脚本不与数据库链接

时间:2016-12-31 16:49:16

标签: php mysql

我有一个脚本,当我转到网站链接(http://kodle.co.uk/login.php)时,脚本会回来:

  

警告:mysql_connect():第12行/home/hkode/public_html/dbconnect.php中的用户'root'@'localhost'(使用>密码:NO)拒绝访问

     

警告:mysql_select_db():第13行/home/hkode/public_html/dbconnect.php中的用户'hkode'@'localhost'(使用>密码:NO)拒绝访问

     

警告:mysql_select_db():无法在第13行的> /home/hkode/public_html/dbconnect.php中建立指向服务器的链接   连接失败:用户'hkode'@'localhost'拒绝访问(使用密码:> NO)

DBCONNECT.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', 'login_base');

$conn = mysql_connect("localhost", "root", "");
$dbcon = mysql_select_db(DBNAME);

if ( !$conn ) {
    die("Connection failed : " . mysql_error());
}

if ( !$dbcon ) {
    die("Database Connection failed : " . mysql_error());
}

5 个答案:

答案 0 :(得分:0)

define('DBPASS', '');

您想要将''替换为'youractualpassword'

然后改变

mysql_connect("localhost", "root", "");

 mysql_connect(DBHOST, DBUSER, DBPASS);

进一步注意评论

// this will avoid mysql_connect() deprecation error.
error_reporting( ~E_DEPRECATED & ~E_NOTICE );
// but I strongly suggest you to use PDO or MySQLi.

建议您不要使用这些方法。如果你完全知道自己在做什么,那么你应该这样做,这似乎就是你没有。

我强烈建议使用像laracasts这样的东西来学习php。 祝你好运

答案 1 :(得分:0)

试试这个

$conn = mysql_connect(DBHOST, DBUSER);
$dbcon = mysql_select_db(DBNAME, $conn);

已修改检查所有密码

答案 2 :(得分:0)

似乎密码不适合用户root,我建议你使用常量来连接你已定义的mysql。 我会重写连接语句和后续语句,如此

$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
    if ( !$conn ) { 
    die("Connection failed : " . mysql_error());
}else{ // connection succesful
   $dbcon = mysql_select_db(DBNAME);
}

答案 3 :(得分:0)

转到您的数据库并检查用户root是否实际上不需要密码。如果是,则将其作为第三个参数插入下面的空单引号中。现在使用下面的代码,你就可以了。新年快乐。

<?php
$con = mysql_connect('REPLACE_THIS_WITH_IP_ADDRESS_OF_YOUR_SERVER', 'root', ''); 
if (!$con) { 
die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db("login_base", $con); 
?>

答案 4 :(得分:0)

不推荐使用mysql你必须使用mysqli或pdo。 mysqli的例子是......

    let showAddressSegueIdentifier = "gotoAddressdetails"
    let showNameSegueIdentifier = "gotoNamedetails"

         //MARK: - Navigation 
          override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
                //Verify segue identifier
                if segue.identifier == showNameSegueIdentifier {
                    if let indexPath = collectionView?.indexPath(for: sender as! UICollectionViewCell) {
                        let controller = segue.destination as! FirstViewController
                        let data = details[indexPath.item]
                        controller.name =  data["name"] as? String ?? ""
                    }
                }else if segue.identifier == showAddressSegueIdentifier {
                    if let indexPath = collectionView?.indexPath(for: sender as! UICollectionViewCell) {
                        let controller = segue.destination as! SecondViewController
                        let data = details[indexPath.item]
                        controller.address =  data["address"] as? String ?? ""
                    }
                }
            }
相关问题