2017-03-31 160 views
0

我不斷收到此錯誤:ini文件正確

警告:mysql_connect()函數:未知MySQL服務器主機 '大象'(1)4

我的ini文件是這樣的:

[Database] 
DBHostName = "localhost" 
DatabaseName = "elephant" 
DBUserName = "elephant" 
DBPassword = "practice" 

[Config] 
ConfigTableName = "stage2_config" 
Skin="purple" 

我的文件讀取ini文件並給出了錯誤是這個與雙粗體星的線。我不知道這裏發生了什麼,爲什麼它說主機不是本地主機。

<?php 
$gv_SystemTest = "<h2>system.php has been included</h2>"; 

$gv_SystemFileInfo = pathinfo(__FILE__); 
$gv_SystemDirectory = $gv_SystemFileInfo['dirname'] . '/'; 
$gv_SystemINIpath = $gv_SystemDirectory . ''; 

$gv_SiteGlobals = parse_ini_file($gv_SystemINIpath . $_SERVER['WIA_SYSTEM_INI'], true); 


function echoContent($p_ContentID) { 
global $gv_SiteGlobals; 

$fv_dbLink = mysql_connect($gv_SiteGlobals['Database']['DBHostName'], 
$gv_SiteGlobals['Database']['DBUserName'], 
$gv_SiteGlobals['Database']['DBPassword']); 
**mysql_connect($gv_SiteGlobals['Database']['DatabaseName']);** 

$fv_TheQuery = "select *from wia_content where content_id = $p_ContentID"; 
+0

'error_log中(的print_r($ gv_SiteGlobals,1));'看什麼回報。 – mkaatman

+0

** mysql_connect($ gv_SiteGlobals ['Database'] ['DatabaseName']); **爲什麼你會使用這一行 –

回答

0

不使用MySQL的使用只的mysqli或PDO

我想你想選擇DB

選擇分貝,你應該在這個被mysql_select_db()

mysql_select_db('foo', $link); 

你的錯誤line

mysql_connect($gv_SiteGlobals['Database']['DatabaseName']); 

應該是形式

mysql_connect('localhost', 'mysql_user', 'mysql_password'); 
1

功能mysql_connect的不允許選擇一個數據庫,你嘗試過這條線。

mysql_connect($gv_SiteGlobals['Database']['DatabaseName']); 

連接並選擇一個數據庫,你需要使用的功能mysql_select_db除了mysql_connect

$link = mysql_connect('host','username','password'); 
$selected = mysql_select_db('database_name', $link); 

http://php.net/manual/en/function.mysql-select-db.php