site initialized; basic catalog lists videos
[living-lab-site.git] / application / libraries / Singleton_db.php
diff --git a/application/libraries/Singleton_db.php b/application/libraries/Singleton_db.php
new file mode 100644 (file)
index 0000000..e9c44c7
--- /dev/null
@@ -0,0 +1,35 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
+
+/**
+ * Library Singleton_db implements a factory that retrieves a single instance
+ * of a Database object for the whole CodeIgniter application.
+ * 
+ * This avoids opening multiple connections to the same database and ensures
+ * that you obtain a Database object only when you need it.
+ *
+ * @category   Controller
+ * @author             Călin-Andrei Burloiu
+ */
+class Singleton_db {
+       
+       private static $db;
+       
+       function __construct()
+       {
+       }
+       
+       public static function connect()
+       {
+               if(!isset(self::$db))
+               {
+                       $CI = & get_instance();
+                       
+                       self::$db = $CI->load->database('default', TRUE);
+               }
+               
+               return self::$db;
+       }
+}
+
+/* End of file Singleton_db.php */
+/* Location: ./application/libraries/Singleton_db.php */