【发布时间】:2017-09-08 23:51:18
【问题描述】:
是否可以使用 codeigniter 中的特定文件为 host、dbname、username 和 password 设置变量?如果可能,如何在特定文件中设置变量连接也可以在config/database.php中读取?我们知道 CI 使用config/database.php 来配置连接。
已编辑
这是代码:
rootweb/index.php
$this->config->load('config', TRUE);
rootweb/config.php
$config['host']="localhost";
$config['dbname']="mydb";
$config['username']="myusername";
$config['password']="mypass";
我也尝试使用这个:
$config['dsn']="postgre://myusername:mypass@localhost/mydb?char_set=utf8&dbcollat=utf8_general_ci&cache_on=true&cachedir=/path/to/cache";
application/config/config.php
include ('config.php');
application/config/database.php
$host = $this->config->item('host', 'config');
$dbname = $this->config->item('dbname', 'config');
$username = $this->config->item('username', 'config');
$password = $this->config->item('password', 'config');
$dsn = $this->config->item('dsn', 'config');
$db['default'] = array(
'dsn' => $dsn,
'hostname' => $host,
'username' => $username,
'password' => $password,
'database' => $dbname,
'dbdriver' => 'postgre',
...
);
并且仍然显示空白页。
【问题讨论】:
-
发布你到目前为止所做的事情
-
你在做什么?仔细阅读 codeigniter 手册。如何创建配置以及在哪里创建配置文件。
标签: php codeigniter