Orion PHP  0.11.12
The PHP5.3 framework
db.php
Go to the documentation of this file.
00001 <?php
00002 
00003 namespace Orion\Core;
00004 
00005 
00006 /**
00007  * \Orion\Core\DB
00008  * 
00009  * Orion DB connector factory.
00010  *
00011  * @author Thibaut Despoulain
00012  * @license BSD 4-clauses
00013  * @version 0.11.12
00014  *
00015  * @static
00016  */
00017 class DB
00018 {
00019 
00020     /**
00021      * Return DB instance or create intitial connection
00022      * @return \Orion\Core\DB\Base
00023      * @access public
00024      */
00025     public static function getConnection()
00026     {
00027         if ( !\Orion::config()->get( 'DB_TYPE' ) )
00028             throw new Exception( 'No database type set in Orion configuration file.', E_ERROR, get_class() );
00029 
00030         try
00031         {
00032             $dbClass = '\\Orion\\Core\\DB\\' . ucfirst( strtolower( \Orion::config()->get( 'DB_TYPE' ) ) );
00033             return $dbClass::getConnection();
00034         }
00035         catch ( Exception $e )
00036         {
00037             throw new Exception( 'Unable to load DB class for [' . \Orion::config()->get( 'DB_TYPE' ) . '] database type.', E_ERROR, get_class() );
00038         }
00039     }
00040 
00041     /**
00042      * Manually close the connection to database
00043      * @return boolean success
00044      */
00045     public static function disconnect()
00046     {
00047         if ( !\Orion::config()->get( 'DB_TYPE' ) )
00048             throw new Exception( 'No database type set in Orion configuration file.', E_ERROR, get_class() );
00049 
00050         try
00051         {
00052             $dbClass = 'DB\\' . ucfirst( strtolower( \Orion::config()->get( 'DB_TYPE' ) ) );
00053             return $dbClass::disconnect();
00054         }
00055         catch ( Exception $e )
00056         {
00057             throw new Exception( 'Unable to load DB class for [' . \Orion::config()->get( 'DB_TYPE' ) . '] database type.', E_ERROR, get_class() );
00058         }
00059     }
00060 
00061 }
00062 
00063 ?>