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