我有一個settings.ini.php包含我的數據庫詳細信息的文件。
;<?php return; ?>
[SQL]
host = localhost
user = root
password =Gohead123$
dbname = nri_demo
而且
**db.class.php**
private function Connect()
{
$this->settings = parse_ini_file("settings.ini.php");
echo '<pre>';
print_r($this->settings);exit;
$dsn = 'mysql:dbname='.$this->settings["dbname"].';host='.$this->settings["host"].'';
try
{
# Read settings from INI file, set UTF8
$this->pdo = new PDO($dsn, $this->settings["user"], $this->settings["password"], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
# We can now log any exceptions on Fatal error.
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
# Disable emulation of prepared statements, use REAL prepared statements instead.
$this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
# Connection succeeded, set the boolean to true.
$this->bConnected = true;
}
catch (PDOException $e)
{
# Write into log
echo $this->ExceptionLog($e->getMessage());
die();
}
}
如果我解析配置(settings.ini.php),密碼沒有顯示文件。如果我更改密碼一樣
[SQL]
host = localhost
user = root
password =Gohead123
dbname = nri_demo
我得到這樣
Array
(
[host] => localhost
[user] => root
[password] => Gohead123
[dbname] => nri_demo
)
我怎樣才能解決這個問題的輸出?請幫助我。
工作對我來說,U盤使用的是哪個版本的PHP? –
@Chethan Ameta PHP版本7.0.15 –
嘗試'parse_ini_file($ str,false,INI_SCANNER_RAW)' –