从 Codeigniter 中的 database.php 页面获取数据库详细信息
我如何从database.php页面获取值? 我的意思是我们可以使用 base_url()
访问基本 url。在 config.php 页面中设置的基本 url 如下所示:
$config['base_url'] = 'example.com';
database.php 中的数据库详细信息如下:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'database_name';
我想访问以下中的此详细信息我的控制器页面。我该怎么做?
How can i get value from database.php page?
I mean we can access base url by using base_url()
.The base url set in config.php page like this :
$config['base_url'] = 'example.com';
The database details in database.php is like:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'database_name';
I want to access the this details in my controller page.How can i do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
还有另一种可行的方法:将数据库设置用作配置数据。
您可以通过将以下行附加到database.php 文件并使用您选择的过滤来做到这一点:
然后您可以像通常加载配置值一样加载数据:
There is another way that would work: you make the db settings available as config data.
You can do that by appending the following lines to the database.php file and use the filtering of your choice:
Then you can load the data as you normally would load config values: