gpt4 book ai didi

php - 如何读取 config.php 文件中的 config.ini 变量

转载 作者:行者123 更新时间:2023-11-30 00:33:42 24 4
gpt4 key购买 nike

所以我纠正了一个使用 config.ini 连接到数据库和其他选项的脚本,但我创建了一个脚本,它是 config.php 并使用相同的数据库。我想从 config.ini 文件中提取一些变量(数据库主机/用户名/密码)并在 config.php 中读取它们。这可能吗?

最佳答案

好吧,把我的头从我的*中拉出来后,我就能弄清楚了!

这就是我的 config.php 文件的样子:
<?
$ini_array = parse_ini_file('config.ini');
$host = $ini_array['database.params.host'];
$username = $ini_array['database.params.username'];
$password = $ini_array['database.params.password'];
$db_name = $ini_array['database.params.dbname'];
mysql_connect($host,$username,$password,$db_name) or die('Could not connect to MySQL');
mysql_select_db($db_name) or die ('could not open db'.mysql_error());
?>

而且它连接得非常好!

关于php - 如何读取 config.php 文件中的 config.ini 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22339360/

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