06-14-2010, 01:47 PM
|
#6 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
The main problem with persistent connection (as I recall) is that they persist beyond the execution of the script, thus if you don't close them properly after you have finished with them you will cause all of the connections in the pool to be used up and therefore giving you a 'Too many connections' type error (im sure its more in depth than that, but I'm at work atm and can't really spend any time to research it). If I remember persistent connections are useful for keeping connections open when the overhead of opening connections is large (i.e. different server for mysql than web server etc) and a few other things, but usually you can avoid using them by better structuring your solution to the problem.
This problem may be better solved by a better program design, i.e. abstracting the DB stuff to another object that persists throughout the execution and can be passed around using dependency injection to objects that need it (you could even make it a singleton if needs be, as suggested by delayedinsanity).
PHP Code:
$pDb = new DBConnection('localhost', 'user', 'pass', 'db');
$pRecord1 = new Record($pDb, $RecordID); $pRecord1->doSomethingWithTheDB();
$pRecord2 = new Record($pDb, $RecordID); $pRecord2->doSomethingWithTheDB();
Or have I missed the problem?
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
Last edited by sketchMedia : 06-15-2010 at 09:04 AM.
Reason: incorrect variable name in example
|
|
|
|