‪TYPO3CMS  10.4
PDOStatement.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Doctrine\DBAL\Driver\PDOException;
21 use Doctrine\DBAL\Driver\PDOStatement as DoctrineDbalPDOStatement;
22 use PDO;
23 
24 class ‪PDOStatement extends DoctrineDbalPDOStatement
25 {
32  protected function ‪mapResourceToString($record)
33  {
34  if (is_array($record)) {
35  return array_map(
36  static function ($value) {
37  if (is_resource($value)) {
38  $value = stream_get_contents($value);
39  }
40 
41  return $value;
42  },
43  $record
44  );
45  }
46 
47  return $record;
48  }
49 
53  public function ‪fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
54  {
55  try {
56  $record = parent::fetch($fetchMode, $cursorOrientation, $cursorOffset);
57  $record = $this->‪mapResourceToString($record);
58  return $record;
59  } catch (\PDOException $exception) {
60  throw new PDOException($exception);
61  }
62  }
63 
67  public function ‪fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
68  {
69  try {
70  $records = parent::fetchAll($fetchMode, $fetchArgument, $ctorArgs);
71 
72  if ($records !== false) {
73  $records = array_map([$this, 'mapResourceToString'], $records);
74  }
75 
76  return $records;
77  } catch (\PDOException $exception) {
78  throw new PDOException($exception);
79  }
80  }
81 
85  public function ‪fetchColumn($columnIndex = 0)
86  {
87  try {
88  $record = parent::fetchColumn($columnIndex);
89  $record = $this->‪mapResourceToString($record);
90  return $record;
91  } catch (\PDOException $exception) {
92  throw new PDOException($exception);
93  }
94  }
95 }
‪TYPO3\CMS\Core\Database\Driver\PDOStatement\fetch
‪fetch($fetchMode=null, $cursorOrientation=PDO::FETCH_ORI_NEXT, $cursorOffset=0)
Definition: PDOStatement.php:53
‪TYPO3\CMS\Core\Database\Driver\PDOStatement\mapResourceToString
‪mixed mapResourceToString($record)
Definition: PDOStatement.php:32
‪TYPO3\CMS\Core\Database\Driver\PDOStatement
Definition: PDOStatement.php:25
‪TYPO3\CMS\Core\Database\Driver\PDOStatement\fetchColumn
‪fetchColumn($columnIndex=0)
Definition: PDOStatement.php:85
‪TYPO3\CMS\Core\Database\Driver
Definition: PDOConnection.php:18
‪TYPO3\CMS\Core\Database\Driver\PDOStatement\fetchAll
‪fetchAll($fetchMode=null, $fetchArgument=null, $ctorArgs=null)
Definition: PDOStatement.php:67