當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Connect::PDOInstance方法代碼示例

本文整理匯總了PHP中Connect::PDOInstance方法的典型用法代碼示例。如果您正苦於以下問題:PHP Connect::PDOInstance方法的具體用法?PHP Connect::PDOInstance怎麽用?PHP Connect::PDOInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Connect的用法示例。


在下文中一共展示了Connect::PDOInstance方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: connecting

 public function connecting()
 {
     $now = new DateTime();
     $mins = $now->getOffset() / 60;
     $sgn = $mins < 0 ? -1 : 1;
     $mins = abs($mins);
     $hrs = floor($mins / 60);
     $mins -= $hrs * 60;
     $offset = sprintf('%+d:%02d', $hrs * $sgn, $mins);
     // @formatter:off
     $this->dsn = $this->parametro['MotorBD'] . ":host=" . $this->parametro['HostBD'] . ";dbname=" . $this->parametro['NameBD'];
     // @formatter:on
     if (!self::$PDOInstance) {
         try {
             self::$PDOInstance = new PDO($this->dsn, $this->parametro['UserBD'], $this->parametro['PassBD']);
             // self::$PDOInstance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
             self::$PDOInstance->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES utf8");
             self::$PDOInstance->setAttribute(PDO::ATTR_PERSISTENT, false);
             self::$PDOInstance->exec("SET time_zone = '{$offset}';");
         } catch (PDOException $e) {
             header('HTTP/1.0 500 Internal Server Error');
             // $this->logs->error("Error al conectar: ", $e->getMessage());
             echo "Error al conectar: " . $e->getMessage() . "<br/>";
             exit;
         }
     }
 }
開發者ID:rafaelurrutia,項目名稱:bmonitor-y-bi,代碼行數:27,代碼來源:libs.connect.php

示例2: connecting

 public function connecting()
 {
     if (isset($this->parametro['MethodConn'])) {
         switch ($this->parametro['MethodConn']) {
             case 'unix_socket':
                 $this->methodconnect = 'unix_socket';
                 break;
             case 'tcp':
                 $this->methodconnect = 'tcp';
                 break;
             default:
                 $this->methodconnect = 'tcp';
                 break;
         }
     } else {
         $this->methodconnect = 'tcp';
     }
     if ($this->methodconnect === 'unix_socket') {
         $this->dsn = $this->parametro['MotorBD'] . ":unix_socket=" . $this->parametro['HostBD'];
         $this->dsn .= ";dbname=" . $this->parametro['NameBD'];
     } else {
         $this->dsn = $this->parametro['MotorBD'] . ":host=" . $this->parametro['HostBD'];
         $this->dsn .= ";dbname=" . $this->parametro['NameBD'];
     }
     if (!self::$PDOInstance) {
         try {
             self::$PDOInstance = new PDO($this->dsn, $this->parametro['UserBD'], $this->parametro['PassBD']);
             self::$PDOInstance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
             self::$PDOInstance->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES utf8");
             self::$PDOInstance->setAttribute(PDO::ATTR_PERSISTENT, false);
         } catch (PDOException $e) {
             $this->logs->error("Error al conectar: ", $e->getMessage());
             die("Error al conectar: " . $e->getMessage() . "<br/>");
         }
     }
 }
開發者ID:rafaelurrutia,項目名稱:bmonitor-y-bi,代碼行數:36,代碼來源:libs.connect.2.php


注:本文中的Connect::PDOInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。