数据库选择失败。phpmyAdmin上的未知数据库错误

数据库选择失败。phpmyAdmin上的未知数据库错误,php,sql,database,phpmyadmin,xampp,Php,Sql,Database,Phpmyadmin,Xampp,我在本地主机上通过PHP脚本选择数据库时遇到问题 我100%确信db名称拼写正确,事实上它在phpmyAdmin上显示得非常好,只有当我试图通过在localhost上运行PHP脚本连接到它时,它才会显示以下错误: Database selection failed Unknown database 'fokrul_justdeals' 我的PHP代码如下: <?php class database{ public $connection; // t

我在本地主机上通过PHP脚本选择数据库时遇到问题

我100%确信db名称拼写正确,事实上它在phpmyAdmin上显示得非常好,只有当我试图通过在localhost上运行PHP脚本连接到它时,它才会显示以下错误:

Database selection failed Unknown database 'fokrul_justdeals'
我的PHP代码如下:

<?php
    class database{
        public $connection;
        // the user for the database
        public $user = 'root';  
        // the pass for the user
        public $pswd = '';
        // the db from where you want to parse the info  
        public $db = 'fokrul_justdeals';
        // the host where db is located
        public $host = 'localhost';

        function __construct(){
            $this->connect();
        } 

        private function connect(){
            $this->connection = mysql_connect("$host", "$user", "$pswd") or die("Database connection failed ". mysql_error());
            if($this->connection){
                // we select the db that we want to work with
                mysql_select_db($this->db, $this->connection) or die("Database selection failed " . mysql_error());
            }
        }

你应该使用

$this->host,$this->user,$this->pswd

不要使用mysql,使用mysqli或pdo,它的deprecatedit仍然显示数据库选择失败。为什么它不能与mysql_connect一起工作?您可以使用任何其他方法连接到数据库,比如mysql工作台或命令行吗?谢谢。现在它说这个数据库连接失败,用户“root”@“localhost”(使用密码:否)的访问被拒绝。您的用户或密码或主机不正确,您可以从上面的代码(PHP)中看到,我使用的是root用户,它没有任何密码,因此它保持为空。我已经检查了phpmyAdmin根用户是否拥有fokrul_justdeals dbNo的完全权限您没有连接。问题不在于你的数据库。你确定你的数据库根用户没有密码吗?是的,它说没有密码。我又查过了
$this->host,$this->user,$this->pswd