当前位置: 首页>>代码示例>>PHP>>正文


PHP PDO::getAttribute方法代码示例

本文整理汇总了PHP中PDO::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP PDO::getAttribute方法的具体用法?PHP PDO::getAttribute怎么用?PHP PDO::getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PDO的用法示例。


在下文中一共展示了PDO::getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: castPdo

 public static function castPdo(\PDO $c, array $a, Stub $stub, $isNested)
 {
     $a = array();
     $errmode = $c->getAttribute(\PDO::ATTR_ERRMODE);
     $c->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     foreach (self::$pdoAttributes as $attr => $values) {
         if (!isset($attr[0])) {
             $attr = $values;
             $values = array();
         }
         try {
             $a[$attr] = 'ERRMODE' === $attr ? $errmode : $c->getAttribute(constant("PDO::ATTR_{$attr}"));
             if ($values && isset($values[$a[$attr]])) {
                 $a[$attr] = new ConstStub($values[$a[$attr]], $a[$attr]);
             }
         } catch (\Exception $m) {
         }
     }
     $m = "~";
     $a = (array) $c + array($m . 'inTransaction' => method_exists($c, 'inTransaction'), $m . 'errorInfo' => $c->errorInfo(), $m . 'attributes' => $a);
     if ($a[$m . 'inTransaction']) {
         $a[$m . 'inTransaction'] = $c->inTransaction();
     } else {
         unset($a[$m . 'inTransaction']);
     }
     if (!isset($a[$m . 'errorInfo'][1], $a[$m . 'errorInfo'][2])) {
         unset($a[$m . 'errorInfo']);
     }
     $c->setAttribute(\PDO::ATTR_ERRMODE, $errmode);
     return $a;
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:31,代码来源:PdoCaster.php

示例2: configure

 protected function configure()
 {
     $this->pdo = new \PDO($this->getOption('dsn'), $this->getOption('username'), $this->getOption('password'));
     $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     $this->driverName = $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
     $this->configureDriver();
 }
开发者ID:rybakit,项目名称:phive-queue,代码行数:7,代码来源:PdoHandler.php

示例3: _performUpdates

 /**
  * executes all the update classes
  */
 private function _performUpdates()
 {
     foreach ($this->_availableUpdates as $rev => $updateList) {
         foreach ($updateList as $u) {
             if (!empty($u[3]) && $this->_conn->getAttribute(PDO::ATTR_DRIVER_NAME) != $u[3]) {
                 continue;
             }
             $updateFormat = $u[5];
             $this->_conn->beginTransaction();
             try {
                 $instance = null;
                 if ($updateFormat == 'sql') {
                     require_once 'Indechse/Maintain/Update/SqlExecute.php';
                     $instance = new Indechse_Maintain_Update_SqlExecute($this->_conn, $rev);
                     $instance->setSql(file_get_contents($this->_updateLocation . '/' . $u[0]));
                 } else {
                     $className = 'Update_' . $u[4];
                     require_once $this->_updateLocation . '/' . $u[0];
                     $instance = new $className($this->_conn, $rev);
                 }
                 $instance->update();
                 $this->_markUpdateComplete($rev, $u[4] . '.' . $u[5]);
                 $this->_conn->commit();
             } catch (Exception $ex) {
                 $this->_conn->rollBack();
                 throw new Exception(sprintf("Update %s (%d) failed with message: %s", $u[0], $rev, $ex->getMessage()), $ex->getCode(), $ex);
             }
         }
     }
 }
开发者ID:nicolask,项目名称:Indechse-DbMaintain,代码行数:33,代码来源:UpdateTool.php

示例4: castPdo

 public static function castPdo(\PDO $c, array $a, Stub $stub, $isNested)
 {
     $attr = array();
     $errmode = $c->getAttribute(\PDO::ATTR_ERRMODE);
     $c->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     foreach (self::$pdoAttributes as $k => $v) {
         if (!isset($k[0])) {
             $k = $v;
             $v = array();
         }
         try {
             $attr[$k] = 'ERRMODE' === $k ? $errmode : $c->getAttribute(constant('PDO::ATTR_' . $k));
             if ($v && isset($v[$attr[$k]])) {
                 $attr[$k] = new ConstStub($v[$attr[$k]], $attr[$k]);
             }
         } catch (\Exception $e) {
         }
     }
     $prefix = Caster::PREFIX_VIRTUAL;
     $a += array($prefix . 'inTransaction' => method_exists($c, 'inTransaction'), $prefix . 'errorInfo' => $c->errorInfo(), $prefix . 'attributes' => new EnumStub($attr));
     if ($a[$prefix . 'inTransaction']) {
         $a[$prefix . 'inTransaction'] = $c->inTransaction();
     } else {
         unset($a[$prefix . 'inTransaction']);
     }
     if (!isset($a[$prefix . 'errorInfo'][1], $a[$prefix . 'errorInfo'][2])) {
         unset($a[$prefix . 'errorInfo']);
     }
     $c->setAttribute(\PDO::ATTR_ERRMODE, $errmode);
     return $a;
 }
开发者ID:sapwoo,项目名称:portfolio,代码行数:31,代码来源:PdoCaster.php

示例5: connect_db

 /**
  * Connect to a database via FS_PDO
  *
  * @param mixed $dsn data source for database connection (array or string)
  * @param       $login
  * @param       $password
  */
 public function connect_db($dsn, $login, $password)
 {
     try {
         $this->db = new PDO($dsn, $login, $password);
     } catch (PDOException $e) {
         $this->debug($e->getMessage());
         $this->file_not_found();
         //program terminates in function file_not_found()
     }
     $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $this->db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
     $driver = $this->db->getAttribute(PDO::ATTR_DRIVER_NAME);
     $this->debug("our driver is {$driver}");
     switch ($driver) {
         case 'mysql':
             $quoter = '`';
             break;
         case 'pgsql':
             if (DEFAULT_DSN_SCHEMA) {
                 $this->db->exec('SET SEARCH_PATH=' . DEFAULT_DSN_SCHEMA);
             }
             $quoter = '"';
             break;
         default:
             $quoter = '';
             break;
     }
     define('DB_FIELD_QUOTE', $quoter);
 }
开发者ID:soulhunter1987,项目名称:freeswitch-curl,代码行数:36,代码来源:fs_curl.php

示例6: __construct

 /**
  * Note if your table name is a reserved word for your target DB you should quote it in the appropriate way e.g.
  * for MySQL enclose the name in `backticks`.
  *
  * @param \PDO   $pdo
  * @param string $tableName
  */
 public function __construct(\PDO $pdo, $tableName)
 {
     $this->pdo = $pdo;
     $this->tableName = $tableName;
     if (\PDO::ERRMODE_EXCEPTION !== $this->pdo->getAttribute(\PDO::ATTR_ERRMODE)) {
         throw new WriterException('Please set the pdo error mode to PDO::ERRMODE_EXCEPTION');
     }
 }
开发者ID:megamanhxh,项目名称:data-import,代码行数:15,代码来源:PdoWriter.php

示例7: getDriver

 /**
  * Returns the driver of database
  *
  * @return string
  */
 public function getDriver()
 {
     try {
         return $this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
     } catch (PDOException $e) {
         ConnectionException::pdoError($e->getMessage(), $e->getCode());
     }
 }
开发者ID:attwframework,项目名称:framework,代码行数:13,代码来源:PDOConnector.php

示例8: pdoGetAttribute

 /**
  * Get a PDO attribute
  *
  * @param int $attr
  * @return bool
  * @throws DatabaseException
  */
 public function pdoGetAttribute(int $attr)
 {
     try {
         return $this->pdo->getAttribute($attr);
     } catch (\PDOException $e) {
         throw DatabaseException::pdoError($e->getMessage());
     }
 }
开发者ID:comelyio,项目名称:comely,代码行数:15,代码来源:AbstractPdo.php

示例9: getServerVersion

 /**
  * Get the server software version.
  * 
  * @return string
  */
 public function getServerVersion()
 {
     try {
         $version = $this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION);
     } catch (\PDOException $e) {
         return NULL;
     }
     return $version;
 }
开发者ID:koolkode,项目名称:database,代码行数:14,代码来源:Connection.php

示例10: __construct

 /**
  * Initializes database connection
  *
  * @param $pixie
  * @param string $config Name of the connection to initialize
  * @return \PHPixie\DB\PDOV\Connection
  */
 public function __construct($pixie, $config)
 {
     parent::__construct($pixie, $config);
     $this->conn = new \PDO($pixie->config->get("db.{$config}.connection"), $pixie->config->get("db.{$config}.user", ''), $pixie->config->get("db.{$config}.password", ''));
     $this->conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     $this->db_type = strtolower(str_replace('PDO_', '', $this->conn->getAttribute(\PDO::ATTR_DRIVER_NAME)));
     if ($this->db_type != 'sqlite') {
         $this->conn->exec("SET NAMES utf8");
     }
 }
开发者ID:brennantom,项目名称:hackazon,代码行数:17,代码来源:Connection.php

示例11: __construct

 /**
  * @param \PDO $connection
  * @param string $cacheTableName
  * @param \MToolkit\Core\MObject $parent
  * @throws \Exception
  */
 public function __construct(\PDO $connection, $cacheTableName = 'MToolkitCache', MObject $parent = null)
 {
     parent::__construct($parent);
     if ($connection->getAttribute(\PDO::ATTR_DRIVER_NAME) != 'sqlite') {
         throw new \Exception('Invalid database connection, required sqlite, passed ' . $connection->getAttribute(\PDO::ATTR_DRIVER_NAME));
     }
     $this->connection = $connection;
     $this->cacheTableName = $cacheTableName;
     $this->init();
 }
开发者ID:mpstyle,项目名称:mtoolkit,代码行数:16,代码来源:MSQLiteCache.php

示例12: __construct

 public final function __construct(\PDO $_connection)
 {
     $this->current_driver = $_connection->getAttribute(\PDO::ATTR_DRIVER_NAME);
     if (!in_array($this->current_driver, $this->approved_pdo_drivers)) {
         throw new \Exception("Incorrect PDO connection");
     }
     if ($_connection->getAttribute(\PDO::ATTR_DRIVER_NAME) == self::DRIVER_SQLITE) {
         $this->sql_select_lock_rows = "";
     }
     $this->sql_select_lock_rows = $this->current_driver != self::DRIVER_SQLITE ? " FOR UPDATE" : "";
     $this->connection = $_connection;
 }
开发者ID:yiqing95,项目名称:php-queue,代码行数:12,代码来源:SqlPdoDriver.php

示例13: getAdapter

 /**
  * Retrieves the table adapter based on the driver used to initialise the PDO object
  * 
  * @param string $tableName
  */
 public function getAdapter($tableName)
 {
     switch ($this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME)) {
         case 'mysql':
             $adapter = new MySQL($this->pdo, $tableName);
             break;
         case 'sqlite':
         default:
             $adapter = new SQLite($this->pdo, $tableName);
             break;
     }
     return $adapter;
 }
开发者ID:vanqard,项目名称:picotable,代码行数:18,代码来源:Connector.php

示例14: __construct

 /**
  * Creates a login attempt and queues it.
  *
  * @param string $username
  * @param string $password
  * @var \PDO $pdo
  * @throws Exception
  */
 public function __construct($username, $password, \PDO $pdo)
 {
     $this->pdo = $pdo;
     if ($this->pdo->getAttribute(PDO::ATTR_ERRMODE) !== PDO::ERRMODE_EXCEPTION) {
         $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     }
     $this->username = $username;
     $this->password = $password;
     if (!$this->isQueueSizeExceeded()) {
         $this->addToQueue();
     } else {
         throw new Exception("Queue size has been exceeded.", 503);
     }
 }
开发者ID:angelesramil79,项目名称:projects,代码行数:22,代码来源:LoginAttempt.php

示例15: _is_connected

 private function _is_connected()
 {
     if ($this->_connection) {
         return $this->_connection->getAttribute(\PDO::ATTR_CONNECTION_STATUS);
     }
     return false;
 }
开发者ID:alex-robert,项目名称:loggr,代码行数:7,代码来源:MySQL.php


注:本文中的PDO::getAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。