CodeIgniter Forums
Unable to connect to the DB - CI 2 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Unable to connect to the DB - CI 2 (/showthread.php?tid=35816)

Pages: 1 2 3


Unable to connect to the DB - CI 2 - El Forum - 11-11-2010

[eluser]Nicholas Hanks[/eluser]
Today I took a snapshot of CI2. Unfortunately I was not able to connect to the DB. I am using PHP 5.3.3


Unable to connect to the DB - CI 2 - El Forum - 11-11-2010

[eluser]Pascal Kriete[/eluser]
I can't replicate (also on 5.3.3). Can you elaborate on what happened?

Did it throw any errors?


Unable to connect to the DB - CI 2 - El Forum - 11-11-2010

[eluser]Nicholas Hanks[/eluser]
I installed CI2 from this site (tip)

---------------------------------------------------------
http://bitbucket.org/ellislab/codeigniter/downloads
---------------------------------------------------------

It is a fresh install in my localhost. So, there is nothing more I can elaborate. This is the error it gives
Code:
A Database Error Occurred

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

Filename: C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\public\mocks\system\database\DB_driver.php

Line Number: 124



Unable to connect to the DB - CI 2 - El Forum - 11-11-2010

[eluser]InsiteFX[/eluser]
Show the code for application/config/database.php

Sounds like a database config setting is wrong!

InsiteFX


Unable to connect to the DB - CI 2 - El Forum - 11-12-2010

[eluser]Nicholas Hanks[/eluser]
I looked at this issue again today. It is not just that CI2 cannot connect to DB - it is also dog slow. I am using CI for 2 years I am familiar with config file and so forth. Having said that I still could be wrong Smile. Remember it is fresh install of CI2 in PHP 5.3.3. Here is my config for DB
Code:
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'test';
$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;



Unable to connect to the DB - CI 2 - El Forum - 11-12-2010

[eluser]InsiteFX[/eluser]
Did you create a database named test?

The error is stating that it cannot connect to your database
with the supplied database settings. Could be wrong password
etc.

InsiteFX


Unable to connect to the DB - CI 2 - El Forum - 11-12-2010

[eluser]Pascal Kriete[/eluser]
Could you try a quick 1.7.2 install with those same settings please? Or better yet, just use plain PHP functions to connect to the database?

The database drivers haven't really been touched for 2.0, so there should be no difference. Our own products all run on trunk, and are connecting fine.

[Edit: Beat by three minutes. I'm not as quick as I used to be.]


Unable to connect to the DB - CI 2 - El Forum - 11-12-2010

[eluser]Nicholas Hanks[/eluser]
If I change CI to 1.7 and change PHP version to 5.2.x then it works fine. So, there is something wrong going on.


Unable to connect to the DB - CI 2 - El Forum - 11-12-2010

[eluser]Nicholas Hanks[/eluser]
Seems like this is the problem with MySQL and PHP 5.3.3. Here are some resources to look at
-------------------------------------------------------
http://stackoverflow.com/questions/4015253/php-5-3-3-mysql-connect-doesnt-work-with-localhost

http://www.ivankristianto.com/web-development/server/pdo-sqlite3-not-working-in-php-5-3-3-and-whmcpanel-11-26-8/1413/
-------------------------------------------------------

Solution I found was this - in database.php file you should set configuration like this
Code:
$db['default']['hostname'] = '127.0.0.1'; //not localhost

Weird huh...


Unable to connect to the DB - CI 2 - El Forum - 11-12-2010

[eluser]InsiteFX[/eluser]
Hi Nicholas,

You must have something setup wrong, I just downloaded the new CI 2.0
and it is working fine with no problems.

I am running XAMPP with PHP 5.3.1 on Windows 7 64-bit.
Also mine is set to localhost.

It could be that your host file is not set to '127.0.0.1'

Try downloading it again and re-install it.

From your screen shot that is saying that MySQL is timing out!
Check your timings in the mysql configuration files.

#interactive_timeout=180
set-variable = interactive_timeout=100

# Reduced wait_timeout to prevent idle clients holding connections.
set-variable = wait_timeout=30

#thread_cache=128
# Reduced it to 32 to prevent memory hogging. Also, see notes below.
set-variable = thread_cache=32

InsiteFX