Home >Backend Development >PHP Tutorial >linux - liunx-centos5.6-apache-x86部署php-CodeIgniter_2.1.4提示无法连接数据库

linux - liunx-centos5.6-apache-x86部署php-CodeIgniter_2.1.4提示无法连接数据库

WBOY
WBOYOriginal
2016-06-06 20:46:571131browse

linux - liunx-centos5.6-apache-x86部署php-CodeIgniter_2.1.4提示无法连接数据库

<code>AcceptPathInfo On
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(.*).html $1 [L]   L]   
</code>

要目录下的.htaccess

config/database.php也是看了又看肯定是没错的了,oncache也关了。
文件名和class名也统统是小写的了,今天上去一看提示无法连接数据库
麻烦帮我看看,谢谢!

<code>$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = '107.160.184.127';
$db['default']['username'] = 'root';
$db['default']['password'] = 'abc136268';
$db['default']['database'] = 'jyz';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;


<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class my_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->load->database('default');
    }
}
</code>

linux - liunx-centos5.6-apache-x86部署php-CodeIgniter_2.1.4提示无法连接数据库

回复内容:

linux - liunx-centos5.6-apache-x86部署php-CodeIgniter_2.1.4提示无法连接数据库

<code>AcceptPathInfo On
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(.*).html $1 [L]   L]   
</code>

要目录下的.htaccess

config/database.php也是看了又看肯定是没错的了,oncache也关了。
文件名和class名也统统是小写的了,今天上去一看提示无法连接数据库
麻烦帮我看看,谢谢!

<code>$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = '107.160.184.127';
$db['default']['username'] = 'root';
$db['default']['password'] = 'abc136268';
$db['default']['database'] = 'jyz';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;


<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class my_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->load->database('default');
    }
}
</code>

linux - liunx-centos5.6-apache-x86部署php-CodeIgniter_2.1.4提示无法连接数据库

建议 hostname 使用 localhost。

另外服务器上数据库是否安装成功?是否启动?
你可以在 cmd / termanal (进你的网站直接出来phpinfo,是Linux系统) 里面输入:

<code class="lang-bash">mysql -uroot -pabc136268
</code>

测试用这个用户名和密码能不能连接上。

您倒是贴个配置文件,再贴个 model 连接数据库的代码呀……

姑且一猜:

在你的 database.php 里,是不是类似这样的?

<code class="lang-php">$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
...
</code>

然后在你的 model 文件里是不是这样的?

<code class="lang-php">class Some_model extends CI_Model {

function __construct() {

    parent::__construct();

    $this->load->database();    // 注意这里
}
</code>

看上面的注释,默认的 database group 叫做 default,所以 $this->load->database() 不传递参数就会读取默认值。如果你显式指明了组名称,比如 $this->load->database('groupname'),那么你就要对比一下看看 database.php 里组名写的是否正确了。

这是在没有代码的前提下猜的,比较常见的错误,具体如何还是要看你代码的。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn