ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPDOStatement.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
32 public function __construct(protected \PDOStatement $pdo_statement)
33 {
34 }
35
36
41 public function fetchRow(int $fetch_mode = ilDBConstants::FETCHMODE_ASSOC): mixed
42 {
43 if ($fetch_mode === ilDBConstants::FETCHMODE_ASSOC) {
44 return $this->pdo_statement->fetch(PDO::FETCH_ASSOC);
45 }
46
47 if ($fetch_mode === ilDBConstants::FETCHMODE_OBJECT) {
48 return $this->pdo_statement->fetch(PDO::FETCH_OBJ);
49 }
50
51 throw new ilDatabaseException("No valid fetch mode given, choose ilDBConstants::FETCHMODE_ASSOC or ilDBConstants::FETCHMODE_OBJECT");
52 }
53
54
58 public function fetch(int $fetch_mode = ilDBConstants::FETCHMODE_ASSOC): mixed
59 {
60 return $this->fetchRow($fetch_mode);
61 }
62
63
67 public function closeCursor(): void
68 {
69 $this->pdo_statement->closeCursor();
70 }
71
72
73 public function rowCount(): int
74 {
75 return $this->pdo_statement->rowCount();
76 }
77
78
79 public function fetchObject(): ?stdClass
80 {
81 return $this->fetch(ilDBConstants::FETCHMODE_OBJECT) ?: null;
82 }
83
84
85 public function fetchAssoc(): ?array
86 {
87 return $this->fetch(ilDBConstants::FETCHMODE_ASSOC) ?: null;
88 }
89
90
91 public function numRows(): int
92 {
93 return $this->pdo_statement->rowCount();
94 }
95
96
97 public function execute(?array $a_data = null): ilDBStatement
98 {
99 $this->pdo_statement->execute($a_data);
100
101 return $this;
102 }
103
104 public function errorCode(): string
105 {
106 return $this->pdo_statement->errorCode();
107 }
108
109 public function errorInfo(): array
110 {
111 return $this->pdo_statement->errorInfo();
112 }
113}
Class ilDatabaseException.
Class ilPDOStatement is a Wrapper Class for PDOStatement.
fetchRow(int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
closeCursor()
Pdo allows for a manual closing of the cursor.
fetch(int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
__construct(protected \PDOStatement $pdo_statement)
execute(?array $a_data=null)
Interface ilDBStatement.
execute(?array $a_data=null)