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


PHP Connection::getPdo方法代码示例

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


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

示例1: __construct

 public function __construct(Connection $connection, $queryString, array $params)
 {
     $time = microtime(TRUE);
     $this->connection = $connection;
     $this->supplementalDriver = $connection->getSupplementalDriver();
     $this->queryString = $queryString;
     $this->params = $params;
     try {
         if (substr($queryString, 0, 2) === '::') {
             $connection->getPdo()->{substr($queryString, 2)}();
         } elseif ($queryString !== NULL) {
             static $types = ['boolean' => PDO::PARAM_BOOL, 'integer' => PDO::PARAM_INT, 'resource' => PDO::PARAM_LOB, 'NULL' => PDO::PARAM_NULL];
             $this->pdoStatement = $connection->getPdo()->prepare($queryString);
             foreach ($params as $key => $value) {
                 $type = gettype($value);
                 $this->pdoStatement->bindValue(is_int($key) ? $key + 1 : $key, $value, isset($types[$type]) ? $types[$type] : PDO::PARAM_STR);
             }
             $this->pdoStatement->setFetchMode(PDO::FETCH_ASSOC);
             $this->pdoStatement->execute();
         }
     } catch (\PDOException $e) {
         $e = $this->supplementalDriver->convertException($e);
         $e->queryString = $queryString;
         throw $e;
     }
     $this->time = microtime(TRUE) - $time;
 }
开发者ID:nette,项目名称:database,代码行数:27,代码来源:ResultSet.php

示例2: inTransaction

 /** @return int Id */
 public function inTransaction()
 {
     $inTransaction = $this->connection->getPdo()->inTransaction();
     if ($inTransaction && $this->id < 1 || !$inTransaction && $this->id > 0) {
         throw new NoTransactionException('Your transaction are out of internal state. Let\'s fix it.');
     }
     return $this->id;
 }
开发者ID:h4kuna,项目名称:transaction,代码行数:9,代码来源:Transaction.php

示例3: __construct

 public function __construct(Connection $connection, $queryString, array $params)
 {
     $time = microtime(TRUE);
     $this->connection = $connection;
     $this->supplementalDriver = $connection->getSupplementalDriver();
     $this->queryString = $queryString;
     $this->params = $params;
     if (substr($queryString, 0, 2) === '::') {
         $connection->getPdo()->{substr($queryString, 2)}();
     } elseif ($queryString !== NULL) {
         $this->pdoStatement = $connection->getPdo()->prepare($queryString);
         $this->pdoStatement->setFetchMode(PDO::FETCH_ASSOC);
         $this->pdoStatement->execute($params);
     }
     $this->time = microtime(TRUE) - $time;
 }
开发者ID:cujan,项目名称:atlashornin,代码行数:16,代码来源:ResultSet.php

示例4: __construct

 /**
  * Driver options:
  *   - charset => character encoding to set (default is utf8 or utf8mb4 since MySQL 5.5.3)
  *   - sqlmode => see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
  */
 public function __construct(Nette\Database\Connection $connection, array $options)
 {
     $this->connection = $connection;
     $charset = isset($options['charset']) ? $options['charset'] : (version_compare($connection->getPdo()->getAttribute(\PDO::ATTR_SERVER_VERSION), '5.5.3', '>=') ? 'utf8mb4' : 'utf8');
     if ($charset) {
         $connection->query("SET NAMES '{$charset}'");
     }
     if (isset($options['sqlmode'])) {
         $connection->query("SET sql_mode='{$options['sqlmode']}'");
     }
 }
开发者ID:ricco24,项目名称:database,代码行数:16,代码来源:MySqlDriver.php

示例5: rollback

 /**
  * Rollback to savepoint.
  *
  * @return void
  * @throws InvalidTransactionException
  */
 public function rollback()
 {
     if (self::$level === 0) {
         throw new InvalidTransactionException('No transaction started');
     }
     self::$level--;
     if (self::$level === 0 || !$this->isSupported()) {
         $this->connection->rollBack();
     } else {
         $this->connection->getPdo()->exec('ROLLBACK TO SAVEPOINT LEVEL' . self::$level);
     }
 }
开发者ID:minetro,项目名称:ntdb,代码行数:18,代码来源:Transaction.php

示例6: loadFromFile

 /**
  * Import SQL dump from file - extremely fast.
  * @return int  count of commands
  */
 public static function loadFromFile(Connection $connection, $file)
 {
     @set_time_limit(0);
     // @ function may be disabled
     $handle = @fopen($file, 'r');
     // @ is escalated to exception
     if (!$handle) {
         throw new Nette\FileNotFoundException("Cannot open file '{$file}'.");
     }
     $count = 0;
     $delimiter = ';';
     $sql = '';
     $pdo = $connection->getPdo();
     // native query without logging
     while (!feof($handle)) {
         $s = rtrim(fgets($handle));
         if (!strncasecmp($s, 'DELIMITER ', 10)) {
             $delimiter = substr($s, 10);
         } elseif (substr($s, -strlen($delimiter)) === $delimiter) {
             $sql .= substr($s, 0, -strlen($delimiter));
             $pdo->exec($sql);
             $sql = '';
             $count++;
         } else {
             $sql .= $s . "\n";
         }
     }
     if (trim($sql) !== '') {
         $pdo->exec($sql);
         $count++;
     }
     fclose($handle);
     return $count;
 }
开发者ID:majky358,项目名称:database,代码行数:38,代码来源:Helpers.php

示例7: __construct

 public function __construct(Nette\Database\Connection $connection, array $options)
 {
     $this->connection = $connection;
     $this->version = $connection->getPdo()->getAttribute(\PDO::ATTR_SERVER_VERSION);
 }
开发者ID:Richmond77,项目名称:learning-nette,代码行数:5,代码来源:SqlsrvDriver.php


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