CodeIgniter Forums
Database Connects Only Sometimes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Database Connects Only Sometimes (/thread-43778.html)



Database Connects Only Sometimes - El Forum - 07-22-2011

[eluser]Unknown[/eluser]
I'm creating my own photo gallery using CI and an API using the REST Client Library (http://philsturgeon.co.uk/news/2009/06/REST-implementation-for-CodeIgniter). To upload the photos from my photo library (using Adobe Photoshop Lightroom) to the gallery, I connect to my API.

The problem is that, sometimes the database connects successfully and the queries are all executed without error. Then, sometimes it seems to stop after the Database is initialized. When it happens, it doesn't execute the function in the controller. I can't figure out why, because it seems like it is failing silently and does not send any response (so the request times out). It seems to connect successfully, since no errors are logged. (Logging is set to level 4 in my config file.) I don't auto load the DB, I load it in the constructor of my controller.

I haven't seen the problem occur on simpler functions that just query the DB. The controller method that the problem is occurring in, accepts an uploaded image, creates two re-sized versions and inserts a row into my DB. I know dealing with images can use CPU resources, but the images are only about 1MB.

This is what the log shows:

Code:
DEBUG - 2011-07-22 02:53:04 --> Config Class Initialized
DEBUG - 2011-07-22 02:53:05 --> Hooks Class Initialized
DEBUG - 2011-07-22 02:53:05 --> Utf8 Class Initialized
DEBUG - 2011-07-22 02:53:05 --> UTF-8 Support Enabled
DEBUG - 2011-07-22 02:53:05 --> URI Class Initialized
DEBUG - 2011-07-22 02:53:05 --> Router Class Initialized
DEBUG - 2011-07-22 02:53:05 --> Output Class Initialized
DEBUG - 2011-07-22 02:53:05 --> Security Class Initialized
DEBUG - 2011-07-22 02:53:05 --> Input Class Initialized
DEBUG - 2011-07-22 02:53:05 --> Global POST and COOKIE data sanitized
DEBUG - 2011-07-22 02:53:05 --> Language Class Initialized
DEBUG - 2011-07-22 02:53:05 --> Loader Class Initialized
DEBUG - 2011-07-22 02:53:05 --> Config file loaded: application/config/wm.php
DEBUG - 2011-07-22 02:53:05 --> Helper loaded: url_helper
DEBUG - 2011-07-22 02:53:05 --> Helper loaded: date_helper
DEBUG - 2011-07-22 02:53:05 --> Controller Class Initialized
DEBUG - 2011-07-22 02:53:05 --> Config file loaded: application/config/rest.php
DEBUG - 2011-07-22 02:53:05 --> Helper loaded: inflector_helper
DEBUG - 2011-07-22 02:53:05 --> Model Class Initialized
DEBUG - 2011-07-22 02:53:05 --> Model Class Initialized
DEBUG - 2011-07-22 02:53:05 --> Database Driver Class Initialized

My dev. environment is as follows:
I have xampp with MySQL 5 installed on one computer and on another computer I have my photo library. So, I'm testng my project across my LAN.

I haven't been able to find anything on Google after hours of searching. I did find this post, [http://ellislab.com/forums/viewthread/125347/#620000] that seems a little similar to my problem, though I am not dealing with any remote databases.

The only thing I can think of is something on the MySQL side, or there's some sort of timeout period.

Anybody out there who can help? Thanks.


Database Connects Only Sometimes - El Forum - 07-24-2011

[eluser]toopay[/eluser]
Just try to autoload the database.


Database Connects Only Sometimes - El Forum - 07-24-2011

[eluser]InsiteFX[/eluser]
Turn this off in application/config/database.php!
Code:
$db['default']['pconnect'] = FALSE;

InsiteFX


Database Connects Only Sometimes - El Forum - 07-26-2011

[eluser]Unknown[/eluser]
Thanks for replying. Before posting my issue, I had already set 'pconnect' to FALSE. I also gave 'autoinit' another try.

This is what my database.php file looked lilke before:

Code:
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '******';
$db['default']['database'] = 'database_one';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$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;

$db['photo_portfolio']['hostname'] = 'localhost';
$db['photo_portfolio']['username'] = 'root';
$db['photo_portfolio']['password'] = '*****';
$db['photo_portfolio']['database'] = 'database_two';
$db['photo_portfolio']['dbdriver'] = 'mysql';
$db['photo_portfolio']['dbprefix'] = '';
$db['photo_portfolio']['pconnect'] = FALSE;
$db['photo_portfolio']['db_debug'] = TRUE;
$db['photo_portfolio']['cache_on'] = FALSE;
$db['photo_portfolio']['cachedir'] = '';
$db['photo_portfolio']['char_set'] = 'utf8';
$db['photo_portfolio']['dbcollat'] = 'utf8_general_ci';
$db['photo_portfolio']['swap_pre'] = '';
$db['photo_portfolio']['autoinit'] = TRUE;
$db['photo_portfolio']['stricton'] = FALSE;

Out of frustration and trying to debug, I modified the DB driver file to print out the $params that were being passed into the DB_driver.php file's constructor. With the $active_group set to 'default' and the 'photo_portfolio' DB set to autoinit, the params of the default database were being passed in. Is this intended or a bug?

After making the changes I just described, this is what changes have been made to the database.php file:

Code:
$active_group = 'default';
$db['photo_portfolio']['autoinit'] = TRUE;

Upon noticing that, I changed the active group to 'photo_portfolio' (which is the database I want to connect to. The problem doesn't seem to occur as often, yet it still occurs.