2014-10-20 118 views
2

我爲故障排除有人和網站的錯誤之一是這樣的:恆變量已經定義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">[email protected]</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">[email protected]</font>'); 
?> 

當我在整個目錄中搜索「serverusername」,在其他任何地方我都找不到

:\xampp\htdocs\employee\inc\db.php on line 5 

H無論如何行:

include 'inc/db.php'; 

存在於衆多的文件。

什麼似乎是問題?我該如何解決它?預先感謝您

回答

1

由於在同一頁上多次包含db.php文件,可能會發生此問題。

試試這個:

include_once 'inc/db.php'; 
0

這種替換代碼:

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