PdoTrait.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Cache\Traits;
  11. use Doctrine\DBAL\Connection;
  12. use Doctrine\DBAL\DBALException;
  13. use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
  14. use Doctrine\DBAL\DriverManager;
  15. use Doctrine\DBAL\Exception;
  16. use Doctrine\DBAL\Exception\TableNotFoundException;
  17. use Doctrine\DBAL\ParameterType;
  18. use Doctrine\DBAL\Schema\Schema;
  19. use Doctrine\DBAL\Statement;
  20. use Symfony\Component\Cache\Exception\InvalidArgumentException;
  21. use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
  22. use Symfony\Component\Cache\Marshaller\MarshallerInterface;
  23. /**
  24. * @internal
  25. */
  26. trait PdoTrait
  27. {
  28. private $marshaller;
  29. private $conn;
  30. private $dsn;
  31. private $driver;
  32. private $serverVersion;
  33. private $table = 'cache_items';
  34. private $idCol = 'item_id';
  35. private $dataCol = 'item_data';
  36. private $lifetimeCol = 'item_lifetime';
  37. private $timeCol = 'item_time';
  38. private $username = '';
  39. private $password = '';
  40. private $connectionOptions = [];
  41. private $namespace;
  42. private function init($connOrDsn, string $namespace, int $defaultLifetime, array $options, ?MarshallerInterface $marshaller)
  43. {
  44. if (isset($namespace[0]) && preg_match('#[^-+.A-Za-z0-9]#', $namespace, $match)) {
  45. throw new InvalidArgumentException(sprintf('Namespace contains "%s" but only characters in [-+.A-Za-z0-9] are allowed.', $match[0]));
  46. }
  47. if ($connOrDsn instanceof \PDO) {
  48. if (\PDO::ERRMODE_EXCEPTION !== $connOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) {
  49. throw new InvalidArgumentException(sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)).', __CLASS__));
  50. }
  51. $this->conn = $connOrDsn;
  52. } elseif ($connOrDsn instanceof Connection) {
  53. $this->conn = $connOrDsn;
  54. } elseif (\is_string($connOrDsn)) {
  55. $this->dsn = $connOrDsn;
  56. } else {
  57. throw new InvalidArgumentException(sprintf('"%s" requires PDO or Doctrine\DBAL\Connection instance or DSN string as first argument, "%s" given.', __CLASS__, \is_object($connOrDsn) ? \get_class($connOrDsn) : \gettype($connOrDsn)));
  58. }
  59. $this->table = $options['db_table'] ?? $this->table;
  60. $this->idCol = $options['db_id_col'] ?? $this->idCol;
  61. $this->dataCol = $options['db_data_col'] ?? $this->dataCol;
  62. $this->lifetimeCol = $options['db_lifetime_col'] ?? $this->lifetimeCol;
  63. $this->timeCol = $options['db_time_col'] ?? $this->timeCol;
  64. $this->username = $options['db_username'] ?? $this->username;
  65. $this->password = $options['db_password'] ?? $this->password;
  66. $this->connectionOptions = $options['db_connection_options'] ?? $this->connectionOptions;
  67. $this->namespace = $namespace;
  68. $this->marshaller = $marshaller ?? new DefaultMarshaller();
  69. parent::__construct($namespace, $defaultLifetime);
  70. }
  71. /**
  72. * Creates the table to store cache items which can be called once for setup.
  73. *
  74. * Cache ID are saved in a column of maximum length 255. Cache data is
  75. * saved in a BLOB.
  76. *
  77. * @throws \PDOException When the table already exists
  78. * @throws DBALException When the table already exists
  79. * @throws Exception When the table already exists
  80. * @throws \DomainException When an unsupported PDO driver is used
  81. */
  82. public function createTable()
  83. {
  84. // connect if we are not yet
  85. $conn = $this->getConnection();
  86. if ($conn instanceof Connection) {
  87. $types = [
  88. 'mysql' => 'binary',
  89. 'sqlite' => 'text',
  90. 'pgsql' => 'string',
  91. 'oci' => 'string',
  92. 'sqlsrv' => 'string',
  93. ];
  94. if (!isset($types[$this->driver])) {
  95. throw new \DomainException(sprintf('Creating the cache table is currently not implemented for PDO driver "%s".', $this->driver));
  96. }
  97. $schema = new Schema();
  98. $table = $schema->createTable($this->table);
  99. $table->addColumn($this->idCol, $types[$this->driver], ['length' => 255]);
  100. $table->addColumn($this->dataCol, 'blob', ['length' => 16777215]);
  101. $table->addColumn($this->lifetimeCol, 'integer', ['unsigned' => true, 'notnull' => false]);
  102. $table->addColumn($this->timeCol, 'integer', ['unsigned' => true]);
  103. $table->setPrimaryKey([$this->idCol]);
  104. foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) {
  105. if (method_exists($conn, 'executeStatement')) {
  106. $conn->executeStatement($sql);
  107. } else {
  108. $conn->exec($sql);
  109. }
  110. }
  111. return;
  112. }
  113. switch ($this->driver) {
  114. case 'mysql':
  115. // We use varbinary for the ID column because it prevents unwanted conversions:
  116. // - character set conversions between server and client
  117. // - trailing space removal
  118. // - case-insensitivity
  119. // - language processing like é == e
  120. $sql = "CREATE TABLE $this->table ($this->idCol VARBINARY(255) NOT NULL PRIMARY KEY, $this->dataCol MEDIUMBLOB NOT NULL, $this->lifetimeCol INTEGER UNSIGNED, $this->timeCol INTEGER UNSIGNED NOT NULL) COLLATE utf8_bin, ENGINE = InnoDB";
  121. break;
  122. case 'sqlite':
  123. $sql = "CREATE TABLE $this->table ($this->idCol TEXT NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
  124. break;
  125. case 'pgsql':
  126. $sql = "CREATE TABLE $this->table ($this->idCol VARCHAR(255) NOT NULL PRIMARY KEY, $this->dataCol BYTEA NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
  127. break;
  128. case 'oci':
  129. $sql = "CREATE TABLE $this->table ($this->idCol VARCHAR2(255) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
  130. break;
  131. case 'sqlsrv':
  132. $sql = "CREATE TABLE $this->table ($this->idCol VARCHAR(255) NOT NULL PRIMARY KEY, $this->dataCol VARBINARY(MAX) NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
  133. break;
  134. default:
  135. throw new \DomainException(sprintf('Creating the cache table is currently not implemented for PDO driver "%s".', $this->driver));
  136. }
  137. if ($conn instanceof Connection && method_exists($conn, 'executeStatement')) {
  138. $conn->executeStatement($sql);
  139. } else {
  140. $conn->exec($sql);
  141. }
  142. }
  143. /**
  144. * {@inheritdoc}
  145. */
  146. public function prune()
  147. {
  148. $deleteSql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= :time";
  149. if ('' !== $this->namespace) {
  150. $deleteSql .= " AND $this->idCol LIKE :namespace";
  151. }
  152. $connection = $this->getConnection();
  153. $useDbalConstants = $connection instanceof Connection;
  154. try {
  155. $delete = $connection->prepare($deleteSql);
  156. } catch (TableNotFoundException $e) {
  157. return true;
  158. } catch (\PDOException $e) {
  159. return true;
  160. }
  161. $delete->bindValue(':time', time(), $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
  162. if ('' !== $this->namespace) {
  163. $delete->bindValue(':namespace', sprintf('%s%%', $this->namespace), $useDbalConstants ? ParameterType::STRING : \PDO::PARAM_STR);
  164. }
  165. try {
  166. // Doctrine DBAL ^2.13 || >= 3.1
  167. if ($delete instanceof Statement && method_exists($delete, 'executeStatement')) {
  168. $delete->executeStatement();
  169. return true;
  170. }
  171. return $delete->execute();
  172. } catch (TableNotFoundException $e) {
  173. return true;
  174. } catch (\PDOException $e) {
  175. return true;
  176. }
  177. }
  178. /**
  179. * {@inheritdoc}
  180. */
  181. protected function doFetch(array $ids)
  182. {
  183. $connection = $this->getConnection();
  184. $useDbalConstants = $connection instanceof Connection;
  185. $now = time();
  186. $expired = [];
  187. $sql = str_pad('', (\count($ids) << 1) - 1, '?,');
  188. $sql = "SELECT $this->idCol, CASE WHEN $this->lifetimeCol IS NULL OR $this->lifetimeCol + $this->timeCol > ? THEN $this->dataCol ELSE NULL END FROM $this->table WHERE $this->idCol IN ($sql)";
  189. $stmt = $connection->prepare($sql);
  190. $stmt->bindValue($i = 1, $now, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
  191. foreach ($ids as $id) {
  192. $stmt->bindValue(++$i, $id);
  193. }
  194. $result = $stmt->execute();
  195. if (\is_object($result)) {
  196. $result = $result->iterateNumeric();
  197. } else {
  198. $stmt->setFetchMode(\PDO::FETCH_NUM);
  199. $result = $stmt;
  200. }
  201. foreach ($result as $row) {
  202. if (null === $row[1]) {
  203. $expired[] = $row[0];
  204. } else {
  205. yield $row[0] => $this->marshaller->unmarshall(\is_resource($row[1]) ? stream_get_contents($row[1]) : $row[1]);
  206. }
  207. }
  208. if ($expired) {
  209. $sql = str_pad('', (\count($expired) << 1) - 1, '?,');
  210. $sql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= ? AND $this->idCol IN ($sql)";
  211. $stmt = $connection->prepare($sql);
  212. $stmt->bindValue($i = 1, $now, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
  213. foreach ($expired as $id) {
  214. $stmt->bindValue(++$i, $id);
  215. }
  216. $stmt->execute();
  217. }
  218. }
  219. /**
  220. * {@inheritdoc}
  221. */
  222. protected function doHave($id)
  223. {
  224. $connection = $this->getConnection();
  225. $useDbalConstants = $connection instanceof Connection;
  226. $sql = "SELECT 1 FROM $this->table WHERE $this->idCol = :id AND ($this->lifetimeCol IS NULL OR $this->lifetimeCol + $this->timeCol > :time)";
  227. $stmt = $connection->prepare($sql);
  228. $stmt->bindValue(':id', $id);
  229. $stmt->bindValue(':time', time(), $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
  230. $result = $stmt->execute();
  231. return (bool) (\is_object($result) ? $result->fetchOne() : $stmt->fetchColumn());
  232. }
  233. /**
  234. * {@inheritdoc}
  235. */
  236. protected function doClear($namespace)
  237. {
  238. $conn = $this->getConnection();
  239. if ('' === $namespace) {
  240. if ('sqlite' === $this->driver) {
  241. $sql = "DELETE FROM $this->table";
  242. } else {
  243. $sql = "TRUNCATE TABLE $this->table";
  244. }
  245. } else {
  246. $sql = "DELETE FROM $this->table WHERE $this->idCol LIKE '$namespace%'";
  247. }
  248. try {
  249. if ($conn instanceof Connection && method_exists($conn, 'executeStatement')) {
  250. $conn->executeStatement($sql);
  251. } else {
  252. $conn->exec($sql);
  253. }
  254. } catch (TableNotFoundException $e) {
  255. } catch (\PDOException $e) {
  256. }
  257. return true;
  258. }
  259. /**
  260. * {@inheritdoc}
  261. */
  262. protected function doDelete(array $ids)
  263. {
  264. $sql = str_pad('', (\count($ids) << 1) - 1, '?,');
  265. $sql = "DELETE FROM $this->table WHERE $this->idCol IN ($sql)";
  266. try {
  267. $stmt = $this->getConnection()->prepare($sql);
  268. $stmt->execute(array_values($ids));
  269. } catch (TableNotFoundException $e) {
  270. } catch (\PDOException $e) {
  271. }
  272. return true;
  273. }
  274. /**
  275. * {@inheritdoc}
  276. */
  277. protected function doSave(array $values, int $lifetime)
  278. {
  279. if (!$values = $this->marshaller->marshall($values, $failed)) {
  280. return $failed;
  281. }
  282. $conn = $this->getConnection();
  283. $useDbalConstants = $conn instanceof Connection;
  284. $driver = $this->driver;
  285. $insertSql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time)";
  286. switch (true) {
  287. case 'mysql' === $driver:
  288. $sql = $insertSql." ON DUPLICATE KEY UPDATE $this->dataCol = VALUES($this->dataCol), $this->lifetimeCol = VALUES($this->lifetimeCol), $this->timeCol = VALUES($this->timeCol)";
  289. break;
  290. case 'oci' === $driver:
  291. // DUAL is Oracle specific dummy table
  292. $sql = "MERGE INTO $this->table USING DUAL ON ($this->idCol = ?) ".
  293. "WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?) ".
  294. "WHEN MATCHED THEN UPDATE SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ?";
  295. break;
  296. case 'sqlsrv' === $driver && version_compare($this->getServerVersion(), '10', '>='):
  297. // MERGE is only available since SQL Server 2008 and must be terminated by semicolon
  298. // It also requires HOLDLOCK according to http://weblogs.sqlteam.com/dang/archive/2009/01/31/UPSERT-Race-Condition-With-MERGE.aspx
  299. $sql = "MERGE INTO $this->table WITH (HOLDLOCK) USING (SELECT 1 AS dummy) AS src ON ($this->idCol = ?) ".
  300. "WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?) ".
  301. "WHEN MATCHED THEN UPDATE SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ?;";
  302. break;
  303. case 'sqlite' === $driver:
  304. $sql = 'INSERT OR REPLACE'.substr($insertSql, 6);
  305. break;
  306. case 'pgsql' === $driver && version_compare($this->getServerVersion(), '9.5', '>='):
  307. $sql = $insertSql." ON CONFLICT ($this->idCol) DO UPDATE SET ($this->dataCol, $this->lifetimeCol, $this->timeCol) = (EXCLUDED.$this->dataCol, EXCLUDED.$this->lifetimeCol, EXCLUDED.$this->timeCol)";
  308. break;
  309. default:
  310. $driver = null;
  311. $sql = "UPDATE $this->table SET $this->dataCol = :data, $this->lifetimeCol = :lifetime, $this->timeCol = :time WHERE $this->idCol = :id";
  312. break;
  313. }
  314. $now = time();
  315. $lifetime = $lifetime ?: null;
  316. try {
  317. $stmt = $conn->prepare($sql);
  318. } catch (TableNotFoundException $e) {
  319. if (!$conn->isTransactionActive() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
  320. $this->createTable();
  321. }
  322. $stmt = $conn->prepare($sql);
  323. } catch (\PDOException $e) {
  324. if (!$conn->inTransaction() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
  325. $this->createTable();
  326. }
  327. $stmt = $conn->prepare($sql);
  328. }
  329. if ('sqlsrv' === $driver || 'oci' === $driver) {
  330. $stmt->bindParam(1, $id);
  331. $stmt->bindParam(2, $id);
  332. $stmt->bindParam(3, $data, $useDbalConstants ? ParameterType::LARGE_OBJECT : \PDO::PARAM_LOB);
  333. $stmt->bindValue(4, $lifetime, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
  334. $stmt->bindValue(5, $now, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
  335. $stmt->bindParam(6, $data, $useDbalConstants ? ParameterType::LARGE_OBJECT : \PDO::PARAM_LOB);
  336. $stmt->bindValue(7, $lifetime, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
  337. $stmt->bindValue(8, $now, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
  338. } else {
  339. $stmt->bindParam(':id', $id);
  340. $stmt->bindParam(':data', $data, $useDbalConstants ? ParameterType::LARGE_OBJECT : \PDO::PARAM_LOB);
  341. $stmt->bindValue(':lifetime', $lifetime, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
  342. $stmt->bindValue(':time', $now, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
  343. }
  344. if (null === $driver) {
  345. $insertStmt = $conn->prepare($insertSql);
  346. $insertStmt->bindParam(':id', $id);
  347. $insertStmt->bindParam(':data', $data, $useDbalConstants ? ParameterType::LARGE_OBJECT : \PDO::PARAM_LOB);
  348. $insertStmt->bindValue(':lifetime', $lifetime, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
  349. $insertStmt->bindValue(':time', $now, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
  350. }
  351. foreach ($values as $id => $data) {
  352. try {
  353. $result = $stmt->execute();
  354. } catch (TableNotFoundException $e) {
  355. if (!$conn->isTransactionActive() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
  356. $this->createTable();
  357. }
  358. $result = $stmt->execute();
  359. } catch (\PDOException $e) {
  360. if (!$conn->inTransaction() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
  361. $this->createTable();
  362. }
  363. $result = $stmt->execute();
  364. }
  365. if (null === $driver && !(\is_object($result) ? $result->rowCount() : $stmt->rowCount())) {
  366. try {
  367. $insertStmt->execute();
  368. } catch (DBALException|Exception $e) {
  369. } catch (\PDOException $e) {
  370. // A concurrent write won, let it be
  371. }
  372. }
  373. }
  374. return $failed;
  375. }
  376. /**
  377. * @return \PDO|Connection
  378. */
  379. private function getConnection()
  380. {
  381. if (null === $this->conn) {
  382. if (strpos($this->dsn, '://')) {
  383. if (!class_exists(DriverManager::class)) {
  384. throw new InvalidArgumentException(sprintf('Failed to parse the DSN "%s". Try running "composer require doctrine/dbal".', $this->dsn));
  385. }
  386. $this->conn = DriverManager::getConnection(['url' => $this->dsn]);
  387. } else {
  388. $this->conn = new \PDO($this->dsn, $this->username, $this->password, $this->connectionOptions);
  389. $this->conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
  390. }
  391. }
  392. if (null === $this->driver) {
  393. if ($this->conn instanceof \PDO) {
  394. $this->driver = $this->conn->getAttribute(\PDO::ATTR_DRIVER_NAME);
  395. } else {
  396. $driver = $this->conn->getDriver();
  397. switch (true) {
  398. case $driver instanceof \Doctrine\DBAL\Driver\Mysqli\Driver:
  399. throw new \LogicException(sprintf('The adapter "%s" does not support the mysqli driver, use pdo_mysql instead.', static::class));
  400. case $driver instanceof \Doctrine\DBAL\Driver\AbstractMySQLDriver:
  401. $this->driver = 'mysql';
  402. break;
  403. case $driver instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver:
  404. case $driver instanceof \Doctrine\DBAL\Driver\PDO\SQLite\Driver:
  405. $this->driver = 'sqlite';
  406. break;
  407. case $driver instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver:
  408. case $driver instanceof \Doctrine\DBAL\Driver\PDO\PgSQL\Driver:
  409. $this->driver = 'pgsql';
  410. break;
  411. case $driver instanceof \Doctrine\DBAL\Driver\OCI8\Driver:
  412. case $driver instanceof \Doctrine\DBAL\Driver\PDOOracle\Driver:
  413. case $driver instanceof \Doctrine\DBAL\Driver\PDO\OCI\Driver:
  414. $this->driver = 'oci';
  415. break;
  416. case $driver instanceof \Doctrine\DBAL\Driver\SQLSrv\Driver:
  417. case $driver instanceof \Doctrine\DBAL\Driver\PDOSqlsrv\Driver:
  418. case $driver instanceof \Doctrine\DBAL\Driver\PDO\SQLSrv\Driver:
  419. $this->driver = 'sqlsrv';
  420. break;
  421. case $driver instanceof \Doctrine\DBAL\Driver:
  422. $this->driver = [
  423. 'mssql' => 'sqlsrv',
  424. 'oracle' => 'oci',
  425. 'postgresql' => 'pgsql',
  426. 'sqlite' => 'sqlite',
  427. 'mysql' => 'mysql',
  428. ][$driver->getDatabasePlatform()->getName()] ?? \get_class($driver);
  429. break;
  430. default:
  431. $this->driver = \get_class($driver);
  432. break;
  433. }
  434. }
  435. }
  436. return $this->conn;
  437. }
  438. private function getServerVersion(): string
  439. {
  440. if (null === $this->serverVersion) {
  441. $conn = $this->conn instanceof \PDO ? $this->conn : $this->conn->getWrappedConnection();
  442. if ($conn instanceof \PDO) {
  443. $this->serverVersion = $conn->getAttribute(\PDO::ATTR_SERVER_VERSION);
  444. } elseif ($conn instanceof ServerInfoAwareConnection) {
  445. $this->serverVersion = $conn->getServerVersion();
  446. } else {
  447. $this->serverVersion = '0';
  448. }
  449. }
  450. return $this->serverVersion;
  451. }
  452. }