CodeIgniter error when connecting to any database

2019-08-10 08:08发布

问题:

I just downloaded a fresh copy of CI from their site(version 3.0.3) and simply configured database and loaded it, but i am having error.

Below is my database configuration in config.php

$db['default'] = array(
'dsn'   => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'shortagesdb',
'dbdriver' => 'mysql',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,//(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

);

and here is what i am doing in my controller i-e simply loading database

public function index()
{
    $this->load->database();
    $this->load->view('welcome_message');
}

Nothing fancy here and i am getting this exception no matter what

PHP Fatal error:  Call to undefined function mysql_connect() in D:\Projects\ims\system\database\drivers\mysql\mysql_driver.php on line 136

Any help would be highly appreciated

回答1:

Codeigniter 3 won't support MySQL. MySQL is deprecated in version 3.0

Try this

$db['default'] = array(
'dsn'   => '',
'hostname' => 'localhost',
'username' => 'root', # check username
'password' => '', # check password
'database' => 'shortagesdb', # check DB name is correct
'dbdriver' => 'mysqli', # remove mysql
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'), # remove TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE



回答2:

The problem might be in your php.ini file, go to you php folder and open that file in a text editor. Now find the extensions and uncomment this:

extension=php_mysqli.dll

Also check that you extension path is correctly directed to your ext folder in the php root location.