本文介绍了数据库选择失败。 phpmyAdmin上的未知数据库错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过localhost上的PHP脚本选择我的数据库时遇到问题。

I am having trouble with selecting my database via PHP script on localhost.

我100%确保数据库名称拼写正确,而且实际上它出现在phpmyAdmin只有当我试图连接到它通过在localhost上运行PHP脚本时,它显示以下错误:

I am 100% sure that db name is spelled correctly and infact it appears on phpmyAdmin very well and only when I am trying to connect to it by running a PHP script on localhost it displays the following error:

Database selection failed Unknown database 'fokrul_justdeals'

我的PHP代码在这里:

My PHP code is here:

<?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());
            }
        }

我已读过数千个论坛,因为我会。但是不知道这里出了什么问题?

I have read thousands of forums and I am doing everything as I shall be. But don't know what is going wrong here?

一个有趣的事情是,在所有数据库中,只有系统生成的db'mysql'连接,如果我更改db名称'mysql'in PHP script。

One interesting thing is that out of all databases only system generated db 'mysql' connects if I change the db name to 'mysql' in PHP script.

我已经尝试创建不同的数据库名称,并尝试创建新用户并向其添加完全权限。没有什么为我工作:(

I have tried creating different db names and also tried creating new users and adding full privileges to them. Nothing has worked for me :(

推荐答案

$this->connection = mysql_connect("$host", "$user", "$pswd") or die("Database connection failed ". mysql_error());

您应该使用

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

这篇关于数据库选择失败。 phpmyAdmin上的未知数据库错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 19:11