是config.php坏文件名?

This examples are from lynda php beyond basic

config.php

<?php
    defined('DB_SERVER') ? null : define("DB_SERVER", "localhost");
    defined('DB_USER')   ? null : define("DB_USER", "root");
    defined('DB_PASS')   ? null : define("DB_PASS", "");
    defined('DB_NAME')   ? null : define("DB_NAME", "photo_gallery");
?>

database.php

<?php
require_once('config.php');

class MySQLDatabase {

private $connection;

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

public function open_connection(){
    $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);

    if (!$this->connection) {
        die("Database connection failed: " . mysql_error());
    } else {
        $db_select = mysql_select_db(DB_NAME, $this->connection);

        if (!$db_select) {
            die("Database selection failed: " . mysql_error());
        }
    }
}

public function close_connection(){

    if(isset($this->connection)) {
        mysql_close($this->connection);
        unset($connection);
    }
}

public function query($sql) {
    $result = mysql_query($sql, $this->connection);
    $this->confirm_query($result);
    return $result;
}



private function confirm_query($result){
    if (!$result) {
        die("Database query failed: " . mysql_error());
    }   
}
}

$database = new MySQLDatabase();

?>

index.php

<?php
    require_once("../includes/database.php");

    if (isset($database)) {
        echo "true";
    } else {
        echo "false";
    }

?>

Now here my problem when I tried index.php run it on the browser i get an error error says:

Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 80

Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 166

Notice: Use of undefined constant DB_SERVER - assumed 'DB_SERVER' in C:\xampp\htdocs\photo_gallery\includes\database.php on line 13

Notice: Use of undefined constant DB_USER - assumed 'DB_USER' in C:\xampp\htdocs\photo_gallery\includes\database.php on line 13

Notice: Use of undefined constant DB_PASS - assumed 'DB_PASS' in C:\xampp\htdocs\photo_gallery\includes\database.php on line 13

Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\photo_gallery\includes\database.php on line 13

Warning: mysql_connect() [function.mysql-connect]: [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. (trying to connect via tcp://DB_SERVER:3306) in C:\xampp\htdocs\photo_gallery\includes\database.php on line 13

Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\photo_gallery\includes\database.php on line 13 Database connection failed: php_network_getaddresses: getaddrinfo failed: No such host is known.

I somehow fix the error by renaming config.php

So here's my question why i got this error? is config.php filename the problem? The video tutorial from Lynda php beyond basics didn't get this error.

It might be due to presence of "config.php" and "Config.php" files in same directory. In windows,file names are not case sensitive. In linux, they are.

There is some sort of error with your local configuration, maybe because you have some third party PEAR installed, hence the error message:

Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 166

You should revise what packages and libraries your system use, because this error message is a sign of outdated code (Deprecated). Personally, I use XAMPP on Windows with my project also having config.php in its htdocs folder without any sorts of error like these. The problem is that the linked file is for . On my system, the 166th line reads as follows:

$this->container = new Config_Container('section', 'root');

config.php is a conventional and general name of calling the configuration file, there is no problem with it. Keeping it with this name lowers no security barriers which could be fixed by merely renaming it.

The other errors will be fixed if your project succeeds in loading the configuration file. Also:

Warning:

Please, don't use mysql_* functions to write new code. They are no longer maintained and the community has begun the deprecation process. See the red box?

Instead, you should learn about prepared statements and use either PDO or MySQLi. This article should give some details about deciding which API to use. For PDO, here is a good tutorial.