예제 #1
0
 /**
  * @return object Returns the PDO instance class or create initial connection.
  */
 public static function getInstance($sDsn = NULL, $sUsername = NULL, $sPassword = NULL, $aDriverOptions = NULL, $sPrefix = NULL)
 {
     if (NULL === self::$_oInstance) {
         if (!empty($sDsn)) {
             self::$_sDsn = $sDsn;
         }
         if (!empty($sUsername)) {
             self::$_sUsername = $sUsername;
         }
         if (!empty($sPassword)) {
             self::$_sPassword = $sPassword;
         }
         if (!empty($aDriverOptions)) {
             self::$_aDriverOptions = $aDriverOptions;
         }
         if (!empty($sPrefix)) {
             self::$_sPrefix = $sPrefix;
         }
         self::$_oInstance = new static();
         try {
             self::$_oDb = new \PDO(self::$_sDsn, self::$_sUsername, self::$_sPassword, self::$_aDriverOptions);
             self::$_oDb->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
         } catch (Exception $oE) {
             exit('Error Establishing a Database Connection');
         }
         static::checkMySqlVersion();
     }
     return self::$_oInstance;
 }
예제 #2
0
 /**
  * Free database.
  *
  * @param object \PDOStatement $rStmt Close cursor of PDOStatement class. Default NULL
  * @param boolean $bCloseConnection Close connection of PDO. Default FALSE
  * @return void
  */
 public static function free(\PDOStatement &$rStmt = NULL, $bCloseConnection = FALSE)
 {
     // Close Cursor
     if (NULL !== $rStmt) {
         $rStmt->closeCursor();
         unset($rStmt);
     }
     // Free instance of the PDO object
     if (TRUE === $bCloseConnection) {
         self::$_oInstance = NULL;
     }
 }