vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php line 31

Open in your IDE?
  1. <?php
  2. namespace Doctrine\DBAL\Driver;
  3. use Doctrine\DBAL\ParameterType;
  4. use PDO;
  5. use function assert;
  6. use function func_get_args;
  7. /**
  8.  * PDO implementation of the Connection interface.
  9.  * Used by all PDO-based drivers.
  10.  */
  11. class PDOConnection extends PDO implements ConnectionServerInfoAwareConnection
  12. {
  13.     /**
  14.      * @param string       $dsn
  15.      * @param string|null  $user
  16.      * @param string|null  $password
  17.      * @param mixed[]|null $options
  18.      *
  19.      * @throws PDOException In case of an error.
  20.      */
  21.     public function __construct($dsn$user null$password null, ?array $options null)
  22.     {
  23.         try {
  24.             parent::__construct($dsn, (string) $user, (string) $password, (array) $options);
  25.             $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, []]);
  26.             $this->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
  27.         } catch (\PDOException $exception) {
  28.             throw new PDOException($exception);
  29.         }
  30.     }
  31.     /**
  32.      * {@inheritdoc}
  33.      */
  34.     public function exec($statement)
  35.     {
  36.         try {
  37.             return parent::exec($statement);
  38.         } catch (\PDOException $exception) {
  39.             throw new PDOException($exception);
  40.         }
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      */
  45.     public function getServerVersion()
  46.     {
  47.         return PDO::getAttribute(PDO::ATTR_SERVER_VERSION);
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public function prepare($prepareString$driverOptions = [])
  53.     {
  54.         try {
  55.             return parent::prepare($prepareString$driverOptions);
  56.         } catch (\PDOException $exception) {
  57.             throw new PDOException($exception);
  58.         }
  59.     }
  60.     /**
  61.      * {@inheritdoc}
  62.      */
  63.     public function query()
  64.     {
  65.         $args func_get_args();
  66.         try {
  67.             $stmt parent::query(...$args);
  68.             assert($stmt instanceof \PDOStatement);
  69.             return $stmt;
  70.         } catch (\PDOException $exception) {
  71.             throw new PDOException($exception);
  72.         }
  73.     }
  74.     /**
  75.      * {@inheritdoc}
  76.      */
  77.     public function quote($input$type ParameterType::STRING)
  78.     {
  79.         return parent::quote($input$type);
  80.     }
  81.     /**
  82.      * {@inheritdoc}
  83.      */
  84.     public function lastInsertId($name null)
  85.     {
  86.         try {
  87.             if ($name === null) {
  88.                 return parent::lastInsertId();
  89.             }
  90.             return parent::lastInsertId($name);
  91.         } catch (\PDOException $exception) {
  92.             throw new PDOException($exception);
  93.         }
  94.     }
  95.     /**
  96.      * {@inheritdoc}
  97.      */
  98.     public function requiresQueryForServerVersion()
  99.     {
  100.         return false;
  101.     }
  102. }