php - unable to connect database : Codeigniter

455

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.

616

Answer

Solution:

Probably you are using newxampp orwamp. So it will not supportmysql.

Change this

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

Answer

Solution:

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';
876

Answer

Solution:

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';

559

Answer

Solution:

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

People are also looking for solutions to the problem: php - laravel method in href link?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.