7
/** The PDOStatement associated with this result set. */
8
protected \PDOStatement $statement;
11
* @param \PDOStatement $statement The PDOStatement associated with this result set.
13
public function __construct(\PDOStatement $statement)
15
$this->statement = $statement;
18
public function __destruct()
20
$this->statement->closeCursor();
26
public function count(): int
28
return $this->statement->rowCount();
34
public function all(?callable $callable = null, int $fetchStyle = 0): array
36
if ($callable === null) {
37
return $this->statement->fetchAll($fetchStyle);
40
return $this->statement->fetchAll($fetchStyle | \PDO::FETCH_FUNC, $callable);
43
public function all_group(?bool $uniq = false, ?callable $callable = null): array
45
$fetchStyle = \PDO::FETCH_GROUP | ($uniq ? \PDO::FETCH_UNIQUE : 0);
46
if ($callable === null) {
47
return $this->statement->fetchAll($fetchStyle);
50
return $this->statement->fetchAll($fetchStyle | \PDO::FETCH_FUNC, $callable);
56
public function first(?callable $callable = null): mixed
58
if ($callable !== null) {
59
$result = $this->statement->fetch(\PDO::FETCH_ASSOC);
60
$this->statement->closeCursor();
61
if (\is_array($result)) {
62
$result = \call_user_func_array($callable, $result);
65
$result = $this->statement->fetch();
66
$this->statement->closeCursor();
75
public function next(): mixed
77
return $this->statement->fetch();
81
* Close current cursor
83
public function flush(): bool
85
return $this->statement->closeCursor();
91
* @param int $col 0-indexed number of the column you wish to retrieve
93
public function column(int $col = 0): mixed
95
return $this->statement->fetchColumn($col);
99
* Fetch each result as an associative array
101
public function fetch_assoc(): static
103
$this->statement->setFetchMode(\PDO::FETCH_ASSOC);
109
* Fetch each result as an stdClass object
111
public function fetch_object(): static
113
$this->statement->setFetchMode(\PDO::FETCH_OBJ);
118
public function fetch_named(): static
120
$this->statement->setFetchMode(\PDO::FETCH_NAMED);
125
public function fetch_num(): static
127
$this->statement->setFetchMode(\PDO::FETCH_NUM);
132
public function fetch_both(): static
134
$this->statement->setFetchMode(\PDO::FETCH_BOTH);
139
public function fetch_key_pair(): static
141
$this->statement->setFetchMode(\PDO::FETCH_KEY_PAIR);
146
public function fetch_class(string $class, array $ctorargs = []): static
148
$this->statement->setFetchMode(\PDO::FETCH_CLASS, $class, $ctorargs);
153
public function fetch_custom(\Closure $func): static
155
$func($this->statement);