0

I'm using Codeigniter and I can't connect my database, give me an error: Error connecting database

I just add the library in autoload.php :

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

and this are my settings in database.php

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

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => 'root',
    'database' => 'heroes',
    '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
);

:S any help?

7
  • What library did you add? What are your settings inside application/config/database.php? Please give some more details. Commented Sep 2, 2015 at 20:01
  • I've just updated it Commented Sep 2, 2015 at 20:05
  • Did you make any modifications to index.php , maybe wrong system path? Does the application work without database lib? Commented Sep 2, 2015 at 20:14
  • yes without the library it works Commented Sep 2, 2015 at 20:30
  • try to change hostname 127.0.0.1 instead localhost and check wheter port 3306 is blocked (default mysql port) Commented Sep 2, 2015 at 20:40

1 Answer 1

1

Just I changed localhost by 127.0.0.1:3306

Sign up to request clarification or add additional context in comments.

1 Comment

But this is the answer ... :S

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.