duanpi5733 2013-03-01 21:19
浏览 48
已采纳

数据库选择失败。 phpmyAdmin上的未知数据库错误[关闭]

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

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'

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?

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 :(

  • 写回答

1条回答 默认 最新

  • dtueufe82643 2013-03-01 21:35
    关注
    $this->connection = mysql_connect("$host", "$user", "$pswd") or die("Database connection failed ". mysql_error());
    

    You should use

    $this->host,$this->user,$this->pswd
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据