2

Error that is getting printed out

Unable to connect to your database server using the provided settings.

Filename: core/Loader.php

Line Number: 346

I have been looking through all the other questions and nothing seems to work. Still getting this error. All the info in my database.php file matched up to my info on the mysql server that I am running on the command line. I am also using mysqld and mysql.server start. I have tested the connection on the command line with

mysql -h localhost -uroot -p dbname

And that seems to work on my command line, but it is giving me the error above when I am referencing it on a localhost server I have set up with the codeigniter project. What am i doing wrong? I have double and triple checked naming conventions to make sure that it isn't the issue.

Also, I am on OS X Mavericks

my code in the config file is as follows:

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'PASS';
$db['default']['database'] = 'dbname';
$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'] = TRUE;
$db['default']['stricton'] = FALSE;
11
  • 1
    Your database credentials are likely wrong. What code are you using to connect to it? Commented Jan 9, 2014 at 19:48
  • 1
    When connecting to the mysql server, are you specifying the IP or the Hostname as the database server host? What version of CI are you using? Can you show your config file obfuscating the password? Commented Jan 9, 2014 at 19:49
  • Have you checked the php error log, and the mysql connection log? Commented Jan 9, 2014 at 19:53
  • updated with error log Commented Jan 9, 2014 at 19:55
  • 1
    Could be as simple as PHP or CI not looking for the mysql socket in the right place. Commented Jan 9, 2014 at 19:56

2 Answers 2

6

I have run into this problem frequently myself with CodeIgniter. The usual solution (for me!) is to set 'pconnect' and 'db_debug' to FALSE:

$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;
Sign up to request clarification or add additional context in comments.

Comments

3

I tried to change the following line in my config/database.php file and it worked. (The error your getting means something is wrong with your config/database.php)

'hostname' => '/Applications/MAMP/tmp/mysql/mysql.sock',

Explanation for this behaviour is written here (MySQL on OSX finds mysql.sock wrongly).

Cheers!

Comments

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.