当前位置: 首页>>代码示例>>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;未经允许,请勿转载。