[ Index ] |
PHP Cross Reference of YOURLS |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of Aura for PHP. 5 * 6 * @license https://opensource.org/licenses/MIT MIT 7 * 8 */ 9 namespace Aura\Sql; 10 11 use Aura\Sql\Profiler\Profiler; 12 use Aura\Sql\Profiler\ProfilerInterface; 13 use PDO; 14 15 /** 16 * 17 * Decorates an existing PDO instance with the extended methods. 18 * 19 * @package Aura.Sql 20 * 21 */ 22 class DecoratedPdo extends AbstractExtendedPdo 23 { 24 /** 25 * 26 * Constructor. 27 * 28 * This overrides the parent so that it can take an existing PDO instance 29 * and decorate it with the extended methods. 30 * 31 * @param PDO $pdo An existing PDO instance to decorate. 32 * 33 * @param ProfilerInterface|null $profiler Tracks and logs query profiles. 34 * 35 */ 36 public function __construct(PDO $pdo, ?ProfilerInterface $profiler = null) 37 { 38 $this->pdo = $pdo; 39 40 $this->setProfiler($profiler ?? new Profiler()); 41 42 $driver = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME); 43 $this->setParser($this->newParser($driver)); 44 $this->setQuoteName($driver); 45 } 46 47 public static function connect( 48 string $dsn, 49 ?string $username = null, 50 ?string $password = null, 51 ?array $options = null, 52 ?ProfilerInterface $profiler = null 53 ): static { 54 if (version_compare(PHP_VERSION, '8.4.0', '>=')) { 55 return new static(\PDO::connect($dsn, $username, $password, $options)); 56 } else { 57 return new static(new PDO($dsn, $username, $password, $options), $profiler); 58 } 59 } 60 61 /** 62 * 63 * Connects to the database. 64 * 65 * @return void 66 * 67 */ 68 public function lazyConnect(): void 69 { 70 // already connected 71 } 72 73 /** 74 * 75 * Disconnects from the database; disallowed with decorated PDO connections. 76 * 77 * @return void 78 * 79 * @throws Exception\CannotDisconnect 80 */ 81 public function disconnect(): void 82 { 83 $message = "Cannot disconnect a DecoratedPdo instance."; 84 throw new Exception\CannotDisconnect($message); 85 } 86 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Mar 31 05:10:02 2025 | Cross-referenced by PHPXref 0.7.1 |