Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Doctrine\DBAL\Driver\PDO;
4
 
5
use Doctrine\DBAL\Driver\Result as ResultInterface;
6
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
7
use Doctrine\DBAL\Driver\Statement as StatementInterface;
8
use Doctrine\DBAL\ParameterType;
9
use Doctrine\Deprecations\Deprecation;
10
use PDO;
11
use PDOException;
12
use PDOStatement;
13
 
14
use function assert;
15
 
16
final class Connection implements ServerInfoAwareConnection
17
{
18
    private PDO $connection;
19
 
20
    /** @internal The connection can be only instantiated by its driver. */
21
    public function __construct(PDO $connection)
22
    {
23
        $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
24
 
25
        $this->connection = $connection;
26
    }
27
 
28
    public function exec(string $sql): int
29
    {
30
        try {
31
            $result = $this->connection->exec($sql);
32
 
33
            assert($result !== false);
34
 
35
            return $result;
36
        } catch (PDOException $exception) {
37
            throw Exception::new($exception);
38
        }
39
    }
40
 
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getServerVersion()
45
    {
46
        return $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION);
47
    }
48
 
49
    /**
50
     * {@inheritDoc}
51
     *
52
     * @return Statement
53
     */
54
    public function prepare(string $sql): StatementInterface
55
    {
56
        try {
57
            $stmt = $this->connection->prepare($sql);
58
            assert($stmt instanceof PDOStatement);
59
 
60
            return new Statement($stmt);
61
        } catch (PDOException $exception) {
62
            throw Exception::new($exception);
63
        }
64
    }
65
 
66
    public function query(string $sql): ResultInterface
67
    {
68
        try {
69
            $stmt = $this->connection->query($sql);
70
            assert($stmt instanceof PDOStatement);
71
 
72
            return new Result($stmt);
73
        } catch (PDOException $exception) {
74
            throw Exception::new($exception);
75
        }
76
    }
77
 
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function quote($value, $type = ParameterType::STRING)
82
    {
83
        return $this->connection->quote($value, $type);
84
    }
85
 
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function lastInsertId($name = null)
90
    {
91
        try {
92
            if ($name === null) {
93
                return $this->connection->lastInsertId();
94
            }
95
 
96
            Deprecation::triggerIfCalledFromOutside(
97
                'doctrine/dbal',
98
                'https://github.com/doctrine/dbal/issues/4687',
99
                'The usage of Connection::lastInsertId() with a sequence name is deprecated.',
100
            );
101
 
102
            return $this->connection->lastInsertId($name);
103
        } catch (PDOException $exception) {
104
            throw Exception::new($exception);
105
        }
106
    }
107
 
108
    public function beginTransaction(): bool
109
    {
110
        return $this->connection->beginTransaction();
111
    }
112
 
113
    public function commit(): bool
114
    {
115
        return $this->connection->commit();
116
    }
117
 
118
    public function rollBack(): bool
119
    {
120
        return $this->connection->rollBack();
121
    }
122
 
123
    public function getNativeConnection(): PDO
124
    {
125
        return $this->connection;
126
    }
127
 
128
    /** @deprecated Call {@see getNativeConnection()} instead. */
129
    public function getWrappedConnection(): PDO
130
    {
131
        Deprecation::triggerIfCalledFromOutside(
132
            'doctrine/dbal',
133
            'https://github.com/doctrine/dbal/pull/5037',
134
            '%s is deprecated, call getNativeConnection() instead.',
135
            __METHOD__,
136
        );
137
 
138
        return $this->getNativeConnection();
139
    }
140
}