⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Open MySQL connections



Amgarp
  • profile picture
  • Member

Posted 24 July 2012 - 20:10 PM

Hi,

I'm a relative newby, so I have performed, step by step, the "The newbies grocery CRUD Tutorial" (clean installation of codeigniter 2.1.2 and Grocery CRUD 1.2.3) . With success: in the end I have a nice "employee grid".
And it looks great!

My problem is that every time I start the 'project' I get (on average) 2 [i]new[/i] MySQL connections and they don't go away....

Does this sound familiar, and do you have any idea how I can solve this?

(I am working on my Windows development environment, so I use WAMP for the time being.)

Any help is appreciated.
Thanks

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 24 July 2012 - 20:49 PM

Hello [member='Amgarp'] and welcome to the forum.

Actually I didn't understood your question. What do you mean exactly with:

[quote]My problem is that every time I start the 'project' I get (on average) 2 [i]new[/i] MySQL connections and they don't go away....[/quote]

Can you please attach a print-screen (the attaching is available when you press More Reply Options at this forum) just to understand what do you mean?

Kindest Regards
Johnny

Amgarp
  • profile picture
  • Member

Posted 25 July 2012 - 08:13 AM

Hi Johnny,

Thanks for your quick reply.

I mean that every time I open the example Employee grid I get 1 or 2 new connections to MySQL (I check this with "SHOW PROCESSLIST" in MySQL or simply Threads_connected in phpmyadmin. Same result.).
When I close the browser, these connections remain. When I open my browser again and open the employee grid I get a new connection (and another one if I refresh). This continues untill I get "Too many connections".

I hope this is clear (I don't see how a print-screen can clarify this).
I'm a newby to php/codeigniter and of course Grocery CRUD. Maybe this is not a Grocery CRUD issue, but a MySQL issue, but I don't think so, because my other php-project (without Grocery CRUD) doesn't have this problem.

My apology if I'm waisting your time....

Thanks

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 25 July 2012 - 14:10 PM

You can simply remove:


$this->load->database();


from your constructor and it will work fine. This is only optional just for new users to not forget to have the database connection on autoload.

So your contruct of your controller will look like this:


function __construct()
{
parent::__construct();

/* Standard Libraries */
$this->load->helper('url');
/* ------------------ */

$this->load->library('grocery_CRUD');
}

Amgarp
  • profile picture
  • Member

Posted 26 July 2012 - 13:37 PM

Hi Johnny,

I did the following:[list=1]
[*]Remove
$this->load->database();


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

to the autoload.php
--> still no improvement (number of open connections keeps increasing)
[*]Made a clean Codeigniter installation without Grocery CRUD, but with the database-autoload
--> same problem, so your code is not the problem!! (sorry for waisting your time.....)
[*]Changed
$db['default']['pconnect'] = TRUE;

(Codeigniter default is TRUE and in your newbies tutorial also TRUE)
to
$db['default']['pconnect'] = FALSE;

--> problem solved!!
[/list]

So thanks for you replies!
I think Grocery CRUD is awesome and if I decide to use it in my projects I will definitely make a significant donation.

On suggestion for future improvements: a standard search box on top of every column? (clicking the magnifier glass, selecting a column, typing a search value an click search is a bit too elaborate imho)

Best regards,
Koos