在PHP中存储配置变量的最佳方法是什么?
2022-08-30 17:17:31
我需要在PHP中存储一堆配置信息。
我考虑了以下几点.
// Doesn't seem right.
$mysqlPass = 'password';
// Seems slightly better.
$config = array(
'mysql_pass' => 'password'
);
// Seems dangerous having this data accessible by anything. but it can't be
// changed via this method.
define('MYSQL_PASSWORD', 'password');
// Don't know if this is such a good idea.
class Config
{
const static MYSQL_PASSWORD = 'password';
}
这就是我到目前为止所想到的。我打算将此配置信息导入到我的应用程序中。require /config.inc.php
在存储配置数据方面,什么对您有用,与此相关的最佳实践是什么?