【发布时间】:2016-01-12 04:58:47
【问题描述】:
我想为我的应用程序创建一个简单的安装程序。我创建了一个名为 "installer" 的库,它将检查数据库 'database' => 变量。如果未定义数据库字段,它将重定向到安装文件夹。这是我的脚本:
<?php
class Installer {
public function __construct() {
//get the CI instance
$CI =& get_instance();
$CI->load->database();
//check if databse config set
if ($CI->db->database == "") {
redirect('install');
} else {
if (is_dir('install')) {
echo '<i>Plese delete or rename <b>Install</b> folder</i>';
exit;
}
}
}
}
我已将库设置为自动加载数据库和会话库
$autoload['libraries'] = array('database','session','installer');
它在我的本地主机上运行良好。但是当我第一次将它上传到我的网络服务器时,我得到了 404 错误(因为控制器文件的第一个字母应该大写),然后我已经纠正了这个问题。但是当我到达我的网址http://example.com/demo(我在 public_html/demo/ 目录中的文件)时,它会显示一些错误,例如
A PHP Error was encountered
Severity: Notice
Message: Uninitialized string offset: 0
Filename: mysqli/mysqli_driver.php
Line Number: 109
Backtrace:
File: /home/xxxxx/public_html/demo/application/controllers/Home.php
Line: 25
Function: __construct
File: /home/xxxxx/public_html/demo/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: mysqli::real_connect(): (HY000/1045): Access denied for user ''@'localhost' (using password: NO)
Filename: mysqli/mysqli_driver.php
Line Number: 161
Backtrace:
File: /home/xxxxx/public_html/demo/application/controllers/Home.php
Line: 25
Function: __construct
File: /home/xxxx/public_html/demo/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/xxxxx/public_html/demo/system/core/Exceptions.php:272)
Filename: core/Common.php
Line Number: 568
Backtrace:
File: /home/xxxxxx/public_html/demo/application/controllers/Home.php
Line: 25
Function: __construct
File: /home/xxxxxx/public_html/demo/index.php
Line: 292
Function: require_once
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: controllers/Home.php
Line Number: 25
当我使用它时,它运行良好。但是当我在我的服务器上使用它时,我得到了这个错误。我的数据库配置文件:
$db['default'] = array(
'dsn' => '',
'hostname' => '',
'username' => '',
'password' => '',
'database' => '',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
【问题讨论】:
标签: php codeigniter