When is it the best time to close a database connect? Is it good to close it on every scripting page i do that uses it?

Recommended Answers

When a PHP script is done executing all non-persistent connections will be closed.
Non-persistent connections are made with the _connect database functions so as long as you stick to that, there's nothing to worry about.

Jump to Post

To read more about fatal error:"OUT OF MEMORY" ,Clickhere

Jump to Post

All 7 Replies

When a PHP script is done executing all non-persistent connections will be closed.
Non-persistent connections are made with the _connect database functions so as long as you stick to that, there's nothing to worry about.

okay thanks!...

One more question what is a recursion? And how do i fix those? My website use to read "Out of memory on line 12"?

To read more about fatal error:"OUT OF MEMORY" ,Clickhere

Error is based on coding and logic.
You have to increase your memory limit.
ini_set(’memory_limit’, '20M');

But if your script is in end level recursion, above solution wont work.
Make sure your recursive function has one limit and break somewhere.

okay, so the only thing I have to do is fix the PHP ini file to accept more memory?

When is it the best time to close a database connect? Is it good to close it on every scripting page i do that uses it?

I use a database singleton design pattern. That makes easy with single close throughout the session!

okay thank you! I will read up on that. ^_^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.