Codeigniter 3.0.3数据库配置


Codeigniter 3.0.3 Database configration

我是codeigniter 3.0的新手。我正在我的服务器上上传我的项目。但我面临着一些让我困扰的错误。但它在本地运行良好。我在谷歌上搜索了一下,但没有找到答案。我认为存在一些数据库配置问题。

这是我的数据库.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失败:名称或服务未知文件名:mysqli/mysqli_driver.php行号:161回溯:文件:/home/selectom/public_html/freber/index.php线路:292功能:需要一次

2.

遇到PHP错误严重性:警告消息:mysqli::real_connect():(HY000/2002):php_network_getaddresses:getaddrinfo失败:名称或服务未知文件名:mysqli/mysqli_driver.php行号:161回溯:文件:/home/selectom/public_html/freber/index.php线路:292功能:需要一次

3.

遇到PHP错误严重性:警告消息:无法修改标头信息-标头已由发送(输出开始于/home/selectom/public_html/freber/system/core/Exceptions.php:272)文件名:core/Common.php行号:568回溯:文件:/home/selectom/public_html/freber/index.php线路:292功能:需要一次

4.

发生数据库错误无法使用提供的设置连接到数据库服务器。文件名:core/CodeIgniter.php行号:500

您的代码是错误的

您的代码

$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
);

Mine(数据库配置代码点火器)

$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()
);

更改环境

转到根目录中的index.php。(如果CI3第56行)

define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');

可用环境

  1. 发展
  2. 测试
  3. 生产