gpt4 book ai didi

php - $ 符号的 parse_ini_file 问题

转载 作者:搜寻专家 更新时间:2023-10-30 22:31:48 29 4
gpt4 key购买 nike

我有一个包含我的数据库详细信息的 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
)

我该如何解决这个问题?请帮助我。

最佳答案

尝试使用 parse_ini_file 的第三个参数作为 INI_SCANNER_RAW

parse_ini_file('settings.ini.php', false, INI_SCANNER_RAW)

输出:

Array ( [host] => localhost [user] => root [password] => Gohead123$ [dbname] => nri_demo )

关于php - $ 符号的 parse_ini_file 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42483718/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com