我是codeigniter 3.0的新手。我正在我的服务器上传我的项目。但我面临一些困扰我的错误。但它在当地工作得很好。我用谷歌搜索,但没有找到我的答案。我认为有一些数据库配置问题。
这是我的database.php
$db['default'] = array(
'dsn' => '',
'hostname' => 'http://selectomobile.com/freber',
'username' => 'my username',
'password' => 'mypassword',
'database' => 'mydatabasename',
'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
);
有些错误让我感到恼火。
1
遇到PHP错误 严重性:警告 消息:mysqli :: real_connect():php_network_getaddresses:getaddrinfo failed:名称或服务未知 文件名:mysqli / mysqli_driver.php 行号:161 回溯: 文件:/home/selectom/public_html/freber/index.php 行:292 功能:require_once
2
遇到PHP错误 严重性:警告 消息:mysqli :: real_connect():( HY000 / 2002):php_network_getaddresses:getaddrinfo failed:名称或服务未知 文件名:mysqli / mysqli_driver.php 行号:161 回溯: 文件:/home/selectom/public_html/freber/index.php 行:292 功能:require_once
3
遇到PHP错误 严重性:警告 消息:无法修改标头信息 - 已经发送的标头(输出从/home/selectom/public_html/freber/system/core/Exceptions.php:272开始) 文件名:core / Common.php 行号:568 回溯: 文件:/home/selectom/public_html/freber/index.php 行:292 功能:require_once
4
发生数据库错误 无法使用提供的设置连接到数据库服务器。 文件名:core / CodeIgniter.php 行号:500
答案 0 :(得分:0)
您的代码错误
$db['default'] = array(
'dsn' => '',
'hostname' => 'http://selectomobile.com/freber', # Wrong
'username' => 'my username',
'password' => 'mypassword',
'database' => 'mydatabasename',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE, # don't change this
'db_debug' => (ENVIRONMENT !== 'production'), # Wrong
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE # There is no such config
);
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost', # this should be localhost
'username' => 'root', # username which creates from DB wizard
'password' => '', # password which creates from DB wizard
'database' => 'database_name',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE, # Changed
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array()
);
改变环境
转到root中的index.php
。 (如果CI3第56行)
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
可用环境