Codeigniter Error “Unable to connect to your datab

2020-07-13 09:33发布

When I trying upload this project on my domain m facing error "Unable to connect to your database server using the provided settings"

I have checked my config.php and database.php file and all the information are correct:

 $db['default']['hostname'] = "etc.com";
 $db['default']['username'] = "etc"; 
 $db['default']['password'] = "etc@etc";
 $db['default']['database'] = "visiting_link";
 $db['default']['dbdriver'] = "mysql";
 $db['default']['dbprefix'] = "";
 $db['default']['pconnect'] = TRUE;
 $db['default']['db_debug'] = TRUE;
 $db['default']['cache_on'] = FALSE;
 $db['default']['cachedir'] = "";
 $db['default']['char_set'] = "utf8";
 $db['default']['dbcollat'] = "utf8_general_ci"; 

Is any solution to that problem? please refer any helping material. I am using fileZilla.
Thanks !

8条回答
成全新的幸福
2楼-- · 2020-07-13 10:16

Try setting the 'dbdriver' to 'mysqli'

$db['default']['dbdriver'] = "mysqli";

It's the MySQL Improved Extension (http://php.net/manual/en/book.mysqli.php) and your server may be set to use this rather than the standard MySQL extension.

I've seen this happen a few times when all other settings are correct, as the connection will fail if the wrong driver is selected.

查看更多
ゆ 、 Hurt°
3楼-- · 2020-07-13 10:16

I was getting this error

    <div id="container">
        <h1>A Database Error Occurred</h1>
        <p>Unable to connect to your database server using the provided settings.</p>
        <p>Filename: C:/xampp/htdocs/WORK/Vishal/UI-Demo/system/database/DB_driver.php</p>
        <p>Line Number: 436</p>
    </div>

I resolved this error by change debug option to FALSE in database.php

'db_debug' => (ENVIRONMENT !== 'production'),

TO

'db_debug' => FALSE,

Change this

$db['default'] = array(
'dsn'   => '',
'hostname' => 'XXXX',
'username' => 'XXXX',
'password' => 'XXXX',
'database' => 'XXX',
'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

);

To

$db['default'] = array(
'dsn'   => '',
'hostname' => 'XXXX',
'username' => 'XXXX',
'password' => 'XXXX',
'database' => 'XXX',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE

);

查看更多
叛逆
4楼-- · 2020-07-13 10:19

if u use codeigniter 3 then please use latest version of php. Once i got these errors but then i update my php then it works after successfully setup codeigniter on my project.

And please follow in your application/config/database.php

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'db_bdtimes', // your database name
    '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
);
查看更多
叼着烟拽天下
5楼-- · 2020-07-13 10:23

This solved my problem while deploying a codeigniter CMS on server, although it was working fine in localhost with TRUE attribute. change this line in database.php to look like this :

$db['default']['pconnect'] = FALSE;

Also CHECK if this line matches the collation of your server's database(for all tables as well):

$db['default']['dbcollat'] = "utf8_general_ci";
查看更多
可以哭但决不认输i
6楼-- · 2020-07-13 10:27

Try this $db['default']['hostname'] = "localhost";

查看更多
啃猪蹄的小仙女
7楼-- · 2020-07-13 10:29

Setting "db_debug" to false solved my problem.

I'm using Snow Leopard.

EDIT: db_debug just obfuscated my direction. The solution in my case was just the mysql.sock reference path, as solved on this question: Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in

OS X use /tmp/mysql.sock, and by default php.ini is referencing /var/mysql/mysql.sock. Just creating a symlink solves the problem:

sudo mkdir -p /var/mysql/ && cd /var/mysql/
sudo ln -s /tmp/mysql.sock ./mysql.sock
查看更多
登录 后发表回答