Tushar Niras
Tushar Niras

Reputation: 3863

unable to connect database : Codeigniter

I have noticed some unexpected behavior while connecting MySQL Codeigniter

Here is scenario:

-> I configured database library for autoload. (config/autoload.php)

$autoload['libraries'] = array('database', 'session');

-> But after configuring that, I can't open anything. I mean to say, Controller or View.

Have I done something wrong?

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'password';
$db['default']['database'] = 'myfamilyfirst';
$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';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = FALSE;
$db['default']['stricton'] = FALSE;

I tried to set $db['default']['autoinit'] = TRUE; to $db['default']['autoinit'] = FALSE;

Now I can open the pages but unable to connect the database.

Please help.

Upvotes: 2

Views: 5059

Answers (4)

Abhijit
Abhijit

Reputation: 941

New codeignator version have mysqli dbdriver. If we have add mysql instated mysqli then shows following error.

Message: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

Correct way is : $db['default']['dbdriver'] = 'mysqli';

Upvotes: 1

Dhanesh
Dhanesh

Reputation: 324

In codeignator latest version we need to connect database using Mysqli. So in database file you need to give database driver as mysqli like this,

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

Upvotes: 2

Little Oars
Little Oars

Reputation: 64

Please make sure that your database username and password matches. Sometimes, these little things matters a lot.

Upvotes: 0

Abdulla Nilam
Abdulla Nilam

Reputation: 38584

Probably you are using new xampp or wamp. So it will not support mysql.

Change this

$db['default']['dbdriver'] = 'mysqli'; # Change

Upvotes: 3

Related Questions