Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | 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\Statement as StatementInterface;
7
use Doctrine\DBAL\ParameterType;
8
use Doctrine\Deprecations\Deprecation;
9
use PDOException;
10
use PDOStatement;
11
 
12
use function array_slice;
13
use function func_get_args;
14
use function func_num_args;
15
 
16
final class Statement implements StatementInterface
17
{
18
    private PDOStatement $stmt;
19
 
20
    /** @internal The statement can be only instantiated by its driver connection. */
21
    public function __construct(PDOStatement $stmt)
22
    {
23
        $this->stmt = $stmt;
24
    }
25
 
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function bindValue($param, $value, $type = ParameterType::STRING)
30
    {
31
        if (func_num_args() < 3) {
32
            Deprecation::trigger(
33
                'doctrine/dbal',
34
                'https://github.com/doctrine/dbal/pull/5558',
35
                'Not passing $type to Statement::bindValue() is deprecated.'
36
                    . ' Pass the type corresponding to the parameter being bound.',
37
            );
38
        }
39
 
621 lars 40
        $pdoType = ParameterTypeMap::convertParamType($type);
148 lars 41
 
42
        try {
621 lars 43
            return $this->stmt->bindValue($param, $value, $pdoType);
148 lars 44
        } catch (PDOException $exception) {
45
            throw Exception::new($exception);
46
        }
47
    }
48
 
49
    /**
50
     * {@inheritDoc}
51
     *
52
     * @deprecated Use {@see bindValue()} instead.
53
     *
54
     * @param mixed    $param
55
     * @param mixed    $variable
56
     * @param int      $type
57
     * @param int|null $length
58
     * @param mixed    $driverOptions The usage of the argument is deprecated.
59
     */
60
    public function bindParam(
61
        $param,
62
        &$variable,
63
        $type = ParameterType::STRING,
64
        $length = null,
65
        $driverOptions = null
66
    ): bool {
67
        Deprecation::trigger(
68
            'doctrine/dbal',
69
            'https://github.com/doctrine/dbal/pull/5563',
70
            '%s is deprecated. Use bindValue() instead.',
71
            __METHOD__,
72
        );
73
 
74
        if (func_num_args() < 3) {
75
            Deprecation::trigger(
76
                'doctrine/dbal',
77
                'https://github.com/doctrine/dbal/pull/5558',
78
                'Not passing $type to Statement::bindParam() is deprecated.'
79
                    . ' Pass the type corresponding to the parameter being bound.',
80
            );
81
        }
82
 
83
        if (func_num_args() > 4) {
84
            Deprecation::triggerIfCalledFromOutside(
85
                'doctrine/dbal',
86
                'https://github.com/doctrine/dbal/issues/4533',
87
                'The $driverOptions argument of Statement::bindParam() is deprecated.',
88
            );
89
        }
90
 
621 lars 91
        $pdoType = ParameterTypeMap::convertParamType($type);
148 lars 92
 
93
        try {
94
            return $this->stmt->bindParam(
95
                $param,
96
                $variable,
621 lars 97
                $pdoType,
148 lars 98
                $length ?? 0,
99
                ...array_slice(func_get_args(), 4),
100
            );
101
        } catch (PDOException $exception) {
102
            throw Exception::new($exception);
103
        }
104
    }
105
 
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function execute($params = null): ResultInterface
110
    {
111
        if ($params !== null) {
112
            Deprecation::trigger(
113
                'doctrine/dbal',
114
                'https://github.com/doctrine/dbal/pull/5556',
115
                'Passing $params to Statement::execute() is deprecated. Bind parameters using'
116
                    . ' Statement::bindParam() or Statement::bindValue() instead.',
117
            );
118
        }
119
 
120
        try {
121
            $this->stmt->execute($params);
122
        } catch (PDOException $exception) {
123
            throw Exception::new($exception);
124
        }
125
 
126
        return new Result($this->stmt);
127
    }
128
}