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;
6
 
7
/** @internal */
8
final class FetchUtils
9
{
10
    /**
11
     * @return mixed|false
12
     *
13
     * @throws Exception
14
     */
15
    public static function fetchOne(Result $result)
16
    {
17
        $row = $result->fetchNumeric();
18
 
19
        if ($row === false) {
20
            return false;
21
        }
22
 
23
        return $row[0];
24
    }
25
 
26
    /**
27
     * @return list<list<mixed>>
28
     *
29
     * @throws Exception
30
     */
31
    public static function fetchAllNumeric(Result $result): array
32
    {
33
        $rows = [];
34
 
35
        while (($row = $result->fetchNumeric()) !== false) {
36
            $rows[] = $row;
37
        }
38
 
39
        return $rows;
40
    }
41
 
42
    /**
43
     * @return list<array<string,mixed>>
44
     *
45
     * @throws Exception
46
     */
47
    public static function fetchAllAssociative(Result $result): array
48
    {
49
        $rows = [];
50
 
51
        while (($row = $result->fetchAssociative()) !== false) {
52
            $rows[] = $row;
53
        }
54
 
55
        return $rows;
56
    }
57
 
58
    /**
59
     * @return list<mixed>
60
     *
61
     * @throws Exception
62
     */
63
    public static function fetchFirstColumn(Result $result): array
64
    {
65
        $rows = [];
66
 
67
        while (($row = $result->fetchOne()) !== false) {
68
            $rows[] = $row;
69
        }
70
 
71
        return $rows;
72
    }
73
}