diff options
| author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
| commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
| tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/dbal/src/Driver/SQLSrv/Connection.php | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/SQLSrv/Connection.php')
| -rw-r--r-- | vendor/doctrine/dbal/src/Driver/SQLSrv/Connection.php | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/SQLSrv/Connection.php b/vendor/doctrine/dbal/src/Driver/SQLSrv/Connection.php new file mode 100644 index 0000000..71050f1 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/SQLSrv/Connection.php | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\SQLSrv; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\Connection as ConnectionInterface; | ||
| 8 | use Doctrine\DBAL\Driver\Exception\NoIdentityValue; | ||
| 9 | use Doctrine\DBAL\Driver\SQLSrv\Exception\Error; | ||
| 10 | |||
| 11 | use function sqlsrv_begin_transaction; | ||
| 12 | use function sqlsrv_commit; | ||
| 13 | use function sqlsrv_query; | ||
| 14 | use function sqlsrv_rollback; | ||
| 15 | use function sqlsrv_rows_affected; | ||
| 16 | use function sqlsrv_server_info; | ||
| 17 | use function str_replace; | ||
| 18 | |||
| 19 | final class Connection implements ConnectionInterface | ||
| 20 | { | ||
| 21 | /** | ||
| 22 | * @internal The connection can be only instantiated by its driver. | ||
| 23 | * | ||
| 24 | * @param resource $connection | ||
| 25 | */ | ||
| 26 | public function __construct(private readonly mixed $connection) | ||
| 27 | { | ||
| 28 | } | ||
| 29 | |||
| 30 | public function getServerVersion(): string | ||
| 31 | { | ||
| 32 | $serverInfo = sqlsrv_server_info($this->connection); | ||
| 33 | |||
| 34 | return $serverInfo['SQLServerVersion']; | ||
| 35 | } | ||
| 36 | |||
| 37 | public function prepare(string $sql): Statement | ||
| 38 | { | ||
| 39 | return new Statement($this->connection, $sql); | ||
| 40 | } | ||
| 41 | |||
| 42 | public function query(string $sql): Result | ||
| 43 | { | ||
| 44 | return $this->prepare($sql)->execute(); | ||
| 45 | } | ||
| 46 | |||
| 47 | public function quote(string $value): string | ||
| 48 | { | ||
| 49 | return "'" . str_replace("'", "''", $value) . "'"; | ||
| 50 | } | ||
| 51 | |||
| 52 | public function exec(string $sql): int | ||
| 53 | { | ||
| 54 | $stmt = sqlsrv_query($this->connection, $sql); | ||
| 55 | |||
| 56 | if ($stmt === false) { | ||
| 57 | throw Error::new(); | ||
| 58 | } | ||
| 59 | |||
| 60 | $rowsAffected = sqlsrv_rows_affected($stmt); | ||
| 61 | |||
| 62 | if ($rowsAffected === false) { | ||
| 63 | throw Error::new(); | ||
| 64 | } | ||
| 65 | |||
| 66 | return $rowsAffected; | ||
| 67 | } | ||
| 68 | |||
| 69 | public function lastInsertId(): int|string | ||
| 70 | { | ||
| 71 | $result = $this->query('SELECT @@IDENTITY'); | ||
| 72 | |||
| 73 | $lastInsertId = $result->fetchOne(); | ||
| 74 | |||
| 75 | if ($lastInsertId === null) { | ||
| 76 | throw NoIdentityValue::new(); | ||
| 77 | } | ||
| 78 | |||
| 79 | return $lastInsertId; | ||
| 80 | } | ||
| 81 | |||
| 82 | public function beginTransaction(): void | ||
| 83 | { | ||
| 84 | if (! sqlsrv_begin_transaction($this->connection)) { | ||
| 85 | throw Error::new(); | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | public function commit(): void | ||
| 90 | { | ||
| 91 | if (! sqlsrv_commit($this->connection)) { | ||
| 92 | throw Error::new(); | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | public function rollBack(): void | ||
| 97 | { | ||
| 98 | if (! sqlsrv_rollback($this->connection)) { | ||
| 99 | throw Error::new(); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | /** @return resource */ | ||
| 104 | public function getNativeConnection() | ||
| 105 | { | ||
| 106 | return $this->connection; | ||
| 107 | } | ||
| 108 | } | ||
