Example #1
0
 /**
  * This method returns the connection object.
  * If it has not been yet created, this method
  * instantiates it based on the $connStr, $user and $pass
  * global variables defined in common.inc.php
  * @return PDO the connection object
  */
 static function getConn()
 {
     if (!self::$conn) {
         global $connStr, $user, $pass;
         try {
             self::$conn = new PDO($connStr, $user, $pass);
             self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         } catch (PDOException $e) {
             showHeader('Error');
             showError("Sorry, an error has occurred. Please\n\t\t\t\t\ttry your request later\n" . $e->getMessage());
         }
     }
     return self::$conn;
 }
Example #2
0
 /**
  * Close connection
  *
  * @param NULL
  * @return NULL
  */
 private function Close()
 {
     self::$conn = NULL;
 }
Example #3
0
 public static function initConnection()
 {
     if (!self::$conn) {
         self::$conn = new PDO("mysql:host=" . DB_SERVER . ";dbname=" . DB_NAME . ";", DB_USER, DB_PASSWORD);
         //            self::$conn =  mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD);
         if (!self::$conn) {
             return false;
         }
         //            mysql_select_db(DB_NAME);
     }
     return true;
 }
Example #4
0
 /**
  * 函数名称:close
  * 功能描述:关闭连接
  */
 private function close()
 {
     self::$conn = null;
 }
Example #5
0
 public static function connect()
 {
     if (!self::$conn) {
         self::$conn = PDOWrap::connect();
     }
 }