EllisLab text mark
Advanced Search
     
MySQL : “Unable to connect to your database server using the provided settings.” But I can connect manually.
Posted: 05 March 2008 05:14 PM
Joined: 2008-02-08
5 posts

I have a new CI 1.6.1 install. In my application/config/database.php file I have the host, username, pass, and db names set. The MySQL is version 5.0.2. I have other CI based sites running, and have gotten database connectivity no problems. When I call

$this->load->database() 

From a controller or model, I get: “Unable to connect to your database server using the provided settings.”

However, if I just use the raw PHP:

mysql_connect('mysql.myhost.com','myuser','mypass') or die("uh oh: ".mysql_error());
mysql_select_db('mydb') or die("no db: ".mysql_error()); 

It connects fine, and I can run queries and all is well. I have copy / pasted the working values from the raw PHP into the database.php file, so it’s not a typo or anything of that nature.

That file looks like:

$db['default']['hostname'"mysql.myhost.com";
$db['default']['username'"myuser";
$db['default']['password'"mypass";
$db['default']['database'"mydb";
$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"

php.ini confirms that persistant connections are enabled, charset and collation match.

This is my first 1.6.X site (all my other CI sites are 1.5.x) so is there some “duuuh” setting somewhere I need to set, or?

 
Posted: 05 March 2008 05:46 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-07-30
2144 posts

Have you tried turning off pconnect (even though php.ini says persistent connections are enabled)?

 Signature 

Follow me on twitter here.
MichaelWales.com | MichaelWales.info

 
Posted: 05 March 2008 05:58 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2008-02-08
5 posts
Michael Wales - 05 March 2008 10:46 PM

Have you tried turning off pconnect (even though php.ini says persistent connections are enabled)?

Yup, same issue.

 
Posted: 05 March 2008 06:13 PM   [ # 3 ]   [ Rating: 0 ]
Joined: 2008-02-08
5 posts

OK.. in a very odd and confounding twist, it now works. What did change? I replaced the double quotes around the hostname in the config file with single quotes.

$db['default']['hostname'=  "mysql.myhost.com"

Causes the error while:

$db['default']['hostname'=  'mysql.myhost.com'

Works just fine. No other setting changed or anything.

Now to go bandage my head where I have been smashing it against my desk.

 
Posted: 26 December 2008 10:07 AM   [ # 4 ]   [ Rating: 0 ]
Joined: 2008-06-12
28 posts

This very strange phenomenon happened with me also, I replaced the double quotes with single quotes and that error no longer showed up.

 
Posted: 16 January 2009 12:51 PM   [ # 5 ]   [ Rating: 0 ]
Joined: 2009-01-16
1 posts

I had the same problem too. (I’m using CI 1.7.0)

I think it might have something to do with the server set-up as well. Things worked well on with my old host - then I transfered everything to a new host and received this error.

I changed the double quotes to single ones in the database config file(as suggested earlier) and all seems to work well so far.

 
Posted: 02 February 2010 07:55 AM   [ # 6 ]   [ Rating: 0 ]
Joined: 2010-02-02
1 posts
Michael Wales - 05 March 2008 10:46 PM

Have you tried turning off pconnect (even though php.ini says persistent connections are enabled)?

Had the same problem but w/o persistent connections.
I didn’t even know to look for it.
Turning pconnect off solved it for me.
Thanks Michael

 
Posted: 10 March 2010 07:09 PM   [ # 7 ]   [ Rating: 0 ]
Joined: 2010-03-10
1 posts

Just spent some time having a similar issue…
Thanks to suggestions here, i finally figured that port was missing!

...and that because of default php.ini of osx > “mysql.default_port = “

thanks smile

 
Posted: 27 January 2011 09:46 PM   [ # 8 ]   [ Rating: 0 ]
Joined: 2011-01-27
1 posts

set $db[‘default’][‘pconnect’] = FALSE;

oK~~~~

 
Posted: 04 August 2013 02:23 PM   [ # 9 ]   [ Rating: 0 ]
Joined: 2012-12-25
1 posts

I changed

$db[‘default’][‘db_debug’] = TRUE;

to

$db[‘default’][‘db_debug’] = FALSE;

and its working now smile

 
Posted: 08 August 2013 03:48 PM   [ # 10 ]   [ Rating: 0 ]
Joined: 2013-08-08
1 posts
vishaljadhav - 04 August 2013 02:23 PM

I changed

$db[‘default’][‘db_debug’] = TRUE;

to

$db[‘default’][‘db_debug’] = FALSE;

and its working now smile

This worked for me. Thanks!!