Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace Doctrine\DBAL\Driver\SQLSrv;
6
 
7
use Doctrine\DBAL\Driver\FetchUtils;
8
use Doctrine\DBAL\Driver\Result as ResultInterface;
9
 
10
use function sqlsrv_fetch;
11
use function sqlsrv_fetch_array;
12
use function sqlsrv_num_fields;
13
use function sqlsrv_rows_affected;
14
 
15
use const SQLSRV_FETCH_ASSOC;
16
use const SQLSRV_FETCH_NUMERIC;
17
 
18
final class Result implements ResultInterface
19
{
20
    /** @var resource */
21
    private $statement;
22
 
23
    /**
24
     * @internal The result can be only instantiated by its driver connection or statement.
25
     *
26
     * @param resource $stmt
27
     */
28
    public function __construct($stmt)
29
    {
30
        $this->statement = $stmt;
31
    }
32
 
33
    /**
34
     * {@inheritDoc}
35
     */
36
    public function fetchNumeric()
37
    {
38
        return $this->fetch(SQLSRV_FETCH_NUMERIC);
39
    }
40
 
41
    /**
42
     * {@inheritDoc}
43
     */
44
    public function fetchAssociative()
45
    {
46
        return $this->fetch(SQLSRV_FETCH_ASSOC);
47
    }
48
 
49
    /**
50
     * {@inheritDoc}
51
     */
52
    public function fetchOne()
53
    {
54
        return FetchUtils::fetchOne($this);
55
    }
56
 
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public function fetchAllNumeric(): array
61
    {
62
        return FetchUtils::fetchAllNumeric($this);
63
    }
64
 
65
    /**
66
     * {@inheritDoc}
67
     */
68
    public function fetchAllAssociative(): array
69
    {
70
        return FetchUtils::fetchAllAssociative($this);
71
    }
72
 
73
    /**
74
     * {@inheritDoc}
75
     */
76
    public function fetchFirstColumn(): array
77
    {
78
        return FetchUtils::fetchFirstColumn($this);
79
    }
80
 
81
    public function rowCount(): int
82
    {
83
        $count = sqlsrv_rows_affected($this->statement);
84
 
85
        if ($count !== false) {
86
            return $count;
87
        }
88
 
89
        return 0;
90
    }
91
 
92
    public function columnCount(): int
93
    {
94
        $count = sqlsrv_num_fields($this->statement);
95
 
96
        if ($count !== false) {
97
            return $count;
98
        }
99
 
100
        return 0;
101
    }
102
 
103
    public function free(): void
104
    {
105
        // emulate it by fetching and discarding rows, similarly to what PDO does in this case
106
        // @link http://php.net/manual/en/pdostatement.closecursor.php
107
        // @link https://github.com/php/php-src/blob/php-7.0.11/ext/pdo/pdo_stmt.c#L2075
108
        // deliberately do not consider multiple result sets, since doctrine/dbal doesn't support them
109
        while (sqlsrv_fetch($this->statement)) {
110
        }
111
    }
112
 
113
    /** @return mixed|false */
114
    private function fetch(int $fetchType)
115
    {
116
        return sqlsrv_fetch_array($this->statement, $fetchType) ?? false;
117
    }
118
}