常量变量已经定义了Xampp错误

时间:2014-10-20 06:22:45

标签: php xampp

我正在为某人网站排查故障,其中一个错误是这样的:

Constant serverusername already defined in C:\xampp\htdocs\employee\inc\db.php on line 5

db.php的内容如下:

<?php

//Database Connection Settings
define ('hostnameorservername','localhost'); //Your server name or hostname goes in here
define ('serverusername','root'); //Your database username goes in here
define ('serverpassword','');  //Your database password goes in here
define ('databasenamed','asset');  //Your database name goes in here

global $connection;
$connection = @mysql_connect(hostnameorservername,serverusername,serverpassword) or die('Connection could not be made to the SQL Server. Please report this system error at <font color="blue">info@servername.com</font>');
@mysql_select_db(databasenamed,$connection) or die('Connection could not be made to the database. Please report this system error at <font color="blue">info@servername.com</font>');   
?>

当我在整个目录中搜索“serverusername”时,除了

之外的其他任何地方都找不到它
:\xampp\htdocs\employee\inc\db.php on line 5

但行:

include 'inc/db.php';

存在于众多文件中。

似乎有什么问题?我该如何解决?提前谢谢

2 个答案:

答案 0 :(得分:1)

由于在同一页面上多次包含db.php文件,可能会发生此问题。

试试这个:

    include_once 'inc/db.php';

答案 1 :(得分:0)

用以下代码替换您的代码:

defined('hostnameorservername') or define('hostnameorservername', 'localhost');
defined('serverusername') or define('serverusername', 'root');
defined('serverpassword') or define('serverpassword', '');
defined('databasenamed') or define('databasenamed', 'asset');