yiisoft /
db-mssql
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Yiisoft\Db\Mssql; |
||
| 6 | |||
| 7 | use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection; |
||
| 8 | use Yiisoft\Db\Driver\Pdo\PdoCommandInterface; |
||
| 9 | use Yiisoft\Db\Query\BatchQueryResultInterface; |
||
| 10 | use Yiisoft\Db\Query\QueryInterface; |
||
| 11 | use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; |
||
| 12 | use Yiisoft\Db\Schema\QuoterInterface; |
||
| 13 | use Yiisoft\Db\Schema\SchemaInterface; |
||
| 14 | use Yiisoft\Db\Transaction\TransactionInterface; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Implements a connection to a database via PDO (PHP Data Objects) for MSSQL Server. |
||
| 18 | * |
||
| 19 | * @link https://www.php.net/manual/en/ref.pdo-sqlsrv.php |
||
| 20 | */ |
||
| 21 | final class Connection extends AbstractPdoConnection |
||
| 22 | { |
||
| 23 | 4 | public function createBatchQueryResult(QueryInterface $query, bool $each = false): BatchQueryResultInterface |
|
| 24 | { |
||
| 25 | 4 | return new BatchQueryResult($query, $each); |
|
| 26 | } |
||
| 27 | |||
| 28 | 677 | public function createCommand(string $sql = null, array $params = []): PdoCommandInterface |
|
| 29 | { |
||
| 30 | 677 | $command = new Command($this); |
|
| 31 | |||
| 32 | 677 | if ($sql !== null) { |
|
| 33 | 618 | $command->setSql($sql); |
|
| 34 | } |
||
| 35 | |||
| 36 | 677 | if ($this->logger !== null) { |
|
| 37 | 2 | $command->setLogger($this->logger); |
|
| 38 | } |
||
| 39 | |||
| 40 | 677 | if ($this->profiler !== null) { |
|
| 41 | 3 | $command->setProfiler($this->profiler); |
|
| 42 | } |
||
| 43 | |||
| 44 | 677 | return $command->bindValues($params); |
|
| 45 | } |
||
| 46 | |||
| 47 | 14 | public function createTransaction(): TransactionInterface |
|
| 48 | { |
||
| 49 | 14 | return new Transaction($this); |
|
| 50 | } |
||
| 51 | |||
| 52 | 924 | public function getQueryBuilder(): QueryBuilderInterface |
|
| 53 | { |
||
| 54 | 924 | if ($this->queryBuilder === null) { |
|
| 55 | 924 | $this->queryBuilder = new QueryBuilder( |
|
| 56 | 924 | $this->getQuoter(), |
|
| 57 | 924 | $this->getSchema(), |
|
| 58 | 924 | ); |
|
| 59 | } |
||
| 60 | |||
| 61 | 924 | return $this->queryBuilder; |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 62 | } |
||
| 63 | |||
| 64 | 989 | public function getQuoter(): QuoterInterface |
|
| 65 | { |
||
| 66 | 989 | if ($this->quoter === null) { |
|
| 67 | 989 | $this->quoter = new Quoter(['[', ']'], ['[', ']'], $this->getTablePrefix()); |
|
| 68 | } |
||
| 69 | |||
| 70 | 989 | return $this->quoter; |
|
|
0 ignored issues
–
show
|
|||
| 71 | } |
||
| 72 | |||
| 73 | 935 | public function getSchema(): SchemaInterface |
|
| 74 | { |
||
| 75 | 935 | if ($this->schema === null) { |
|
| 76 | 935 | $this->schema = new Schema($this, $this->schemaCache); |
|
| 77 | } |
||
| 78 | |||
| 79 | 935 | return $this->schema; |
|
|
0 ignored issues
–
show
|
|||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Initializes the DB connection. |
||
| 84 | * |
||
| 85 | * This method is invoked right after the DB connection is established. |
||
| 86 | */ |
||
| 87 | 665 | protected function initConnection(): void |
|
| 88 | { |
||
| 89 | 665 | $this->pdo = $this->driver->createConnection(); |
|
| 90 | } |
||
| 91 | } |
||
| 92 |