douzhigan1687 2012-08-08 11:26 采纳率: 0%
浏览 23

是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.

  • 写回答

2条回答 默认 最新

  • doudao8283 2012-08-08 11:28
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图