getPdo() публичный Метод

public getPdo ( ) : PDO
Результат PDO
Пример #1
0
 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;
 }
Пример #2
0
 /** @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;
 }
Пример #3
0
 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;
 }
Пример #4
0
 /**
  * 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']}'");
     }
 }
Пример #5
0
 /**
  * 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);
     }
 }
Пример #6
0
 /**
  * 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;
 }
Пример #7
0
 public function __construct(Nette\Database\Connection $connection, array $options)
 {
     $this->connection = $connection;
     $this->version = $connection->getPdo()->getAttribute(\PDO::ATTR_SERVER_VERSION);
 }