diff options
| author | 2024-05-13 12:44:35 +0200 | |
|---|---|---|
| committer | 2024-05-13 12:44:35 +0200 | |
| commit | 4f57a46075fc38cffd479ab76b2ea56e9b626926 (patch) | |
| tree | d6d1ed24ae44dce25a8f05c3b06dfcb9c695d709 /lib | |
| parent | e0cc121c7a556126b6c4968cb9efac47ee1382b5 (diff) | |
Auto-update 5038 (#6279)
* Auto-update 5038
https://github.com/FreshRSS/FreshRSS/pull/5038
* PostgreSQL
* Draft for MySQL
* More draft MySQL
* Finalise
* A bit more robust
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Minz/ModelPdo.php | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php index f7a6994c7..b39ae2f81 100644 --- a/lib/Minz/ModelPdo.php +++ b/lib/Minz/ModelPdo.php @@ -238,4 +238,19 @@ class Minz_ModelPdo { public function fetchColumn(string $sql, int $column, array $values = []): ?array { return $this->fetchAny($sql, $values, PDO::FETCH_COLUMN, $column); } + + /** For retrieving a single value without prepared statement such as `SELECT version()` */ + public function fetchValue(string $sql): ?string { + $stm = $this->pdo->query($sql); + if ($stm === false) { + Minz_Log::error('SQL error ' . json_encode($this->pdo->errorInfo()) . ' during ' . $sql); + return null; + } + $columns = $stm->fetchAll(PDO::FETCH_COLUMN, 0); + if ($columns === false) { + Minz_Log::error('SQL error ' . json_encode($stm->errorInfo()) . ' during ' . $sql); + return null; + } + return isset($columns[0]) ? (string)$columns[0] : null; + } } |
