ILIAS  release_8 Revision v8.24
class.ilPDOStatement.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 protected \PDOStatement $pdo_statement;
30
31
35 public function __construct(PDOStatement $pdo_statement)
36 {
37 $this->pdo_statement = $pdo_statement;
38 }
39
40
45 public function fetchRow(int $fetch_mode = ilDBConstants::FETCHMODE_ASSOC)
46 {
47 if ($fetch_mode === ilDBConstants::FETCHMODE_ASSOC) {
48 return $this->pdo_statement->fetch(PDO::FETCH_ASSOC);
49 }
50
51 if ($fetch_mode === ilDBConstants::FETCHMODE_OBJECT) {
52 return $this->pdo_statement->fetch(PDO::FETCH_OBJ);
53 }
54
55 throw new ilDatabaseException("No valid fetch mode given, choose ilDBConstants::FETCHMODE_ASSOC or ilDBConstants::FETCHMODE_OBJECT");
56 }
57
58
62 public function fetch(int $fetch_mode = ilDBConstants::FETCHMODE_ASSOC)
63 {
64 return $this->fetchRow($fetch_mode);
65 }
66
67
71 public function closeCursor(): void
72 {
73 $this->pdo_statement->closeCursor();
74 }
75
76
77 public function rowCount(): int
78 {
79 return $this->pdo_statement->rowCount();
80 }
81
82
83 public function fetchObject(): ?stdClass
84 {
85 return $this->fetch(ilDBConstants::FETCHMODE_OBJECT) ?: null;
86 }
87
88
89 public function fetchAssoc(): ?array
90 {
91 return $this->fetch(ilDBConstants::FETCHMODE_ASSOC) ?: null;
92 }
93
94
95 public function numRows(): int
96 {
97 return $this->pdo_statement->rowCount();
98 }
99
100
101 public function execute(array $a_data = null): ilDBStatement
102 {
103 $this->pdo_statement->execute($a_data);
104
105 return $this;
106 }
107
108 public function errorCode(): string
109 {
110 return $this->pdo_statement->errorCode();
111 }
112
113 public function errorInfo(): array
114 {
115 return $this->pdo_statement->errorInfo();
116 }
117}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPDOStatement is a Wrapper Class for PDOStatement.
__construct(PDOStatement $pdo_statement)
PDOStatement $pdo_statement
fetchRow(int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
closeCursor()
Pdo allows for a manual closing of the cursor.
execute(array $a_data=null)
fetch(int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
execute(array $a_data=null)