From 63e0b2ee7313d0dc0566174db3e09562fd15f28f Mon Sep 17 00:00:00 2001 From: Brian Nesbitt Date: Sat, 4 Aug 2012 00:36:16 -0300 Subject: [PATCH] Added small paragraph on connections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some developers (maybe not newbies, but more coming from other languages) will be wondering if you have to close connections.  I think a quick touch on database connections and their automatic closing on script end is a helpful addition. --- _posts/06-01-01-Databases.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/_posts/06-01-01-Databases.md b/_posts/06-01-01-Databases.md index 15f3df4..eae1d69 100644 --- a/_posts/06-01-01-Databases.md +++ b/_posts/06-01-01-Databases.md @@ -52,6 +52,14 @@ database preventing potential SQL injection attacks. * [Learn about PDO][1] +You should also be aware that database connections use up resources and it was not unheard-of to have resources +exhausted if connections were not implicitly closed, however this was more common in other languages. Using PDO you +can implicitly close the connection by destroying the object by ensuring all remaining references to it are deleted, +ie. set to NULL. If you don't do this explicitly, PHP will automatically close the connection when your script ends +unless of course you are using persistent connections. + +* [Learn about PDO connections][5] + ## Abstraction Layers Many frameworks provide their own abstraction layer which may or may not sit on top of PDO. These will often emulate features for @@ -69,6 +77,7 @@ Some abstraction layers have been built using the PSR-0 namespace standard so ca [2]: http://www.doctrine-project.org/projects/dbal.html [3]: http://framework.zend.com/manual/en/zend.db.html [4]: http://packages.zendframework.com/docs/latest/manual/en/index.html#zend-db +[5]: http://php.net/manual/en/pdo.connections.php [mysql]: http://uk.php.net/mysql [mysqli]: http://uk.php.net/mysqli