【问题标题】:Codeigniter 3.0.3 Database configrationCodeigniter 3.0.3 数据库配置
【发布时间】:2016-04-14 04:51:55
【问题描述】:

我是 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 failed: Name or service not known 文件名: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: Name or service not known 文件名: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

【问题讨论】:

  • 我只是运行 [link] (selectomobile.com/freber)。
  • 如果服务器上有 cPanel,请查看那里的 mysql 服务器地址。这不是您的网站/应用程序链接。也可以在phpmyadmin中查看,或者如果您没有安装cPanel,您可以将其设置为localhost或安装MySQL的服务器的IP地址。

标签: php codeigniter mysqli codeigniter-3


【解决方案1】:

你的代码错了

您的代码

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

我的 (Database Configuration Codeigniter)

$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. 生产

【讨论】:

    猜你喜欢
    • 2017-11-23
    • 2012-06-08
    • 2017-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-05
    • 2017-09-16
    相关资源
    最近更新 更多