[TASK] Deprecate TYPO3\CMS\Core\Database\PdoHelper
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Database / PdoHelper.php
1 <?php
2 namespace TYPO3\CMS\Core\Database;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * A helper class for handling PDO databases
19 *
20 * @deprecated and will be removed in TYPO3 v10.0
21 */
22 class PdoHelper
23 {
24 /**
25 * Pumps the SQL into the database. Use for DDL only.
26 *
27 * Important: key definitions with length specifiers (needed for MySQL) must
28 * be given as "field"(xyz) - no space between double quote and parenthesis -
29 * so they can be removed automatically.
30 *
31 * @param \PDO $databaseHandle
32 * @param string $pdoDriver
33 * @param string $pathAndFilename
34 * @deprecated and will be removed in TYPO3 v10.0
35 */
36 public static function importSql(\PDO $databaseHandle, $pdoDriver, $pathAndFilename)
37 {
38 trigger_error('Class will be removed in TYPO3 v10', E_USER_DEPRECATED);
39 $sql = file($pathAndFilename, FILE_IGNORE_NEW_LINES & FILE_SKIP_EMPTY_LINES);
40 // Remove MySQL style key length delimiters (yuck!) if we are not setting up a MySQL db
41 if (substr($pdoDriver, 0, 5) !== 'mysql') {
42 $sql = preg_replace('/"\\([0-9]+\\)/', '"', $sql);
43 }
44 $statement = '';
45 foreach ($sql as $line) {
46 $statement .= ' ' . trim($line);
47 if (substr($statement, -1) === ';') {
48 $databaseHandle->exec($statement);
49 $statement = '';
50 }
51 }
52 }
53 }