1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /** |
||
6 | * neuralyzer : Data Anonymization Library and CLI Tool |
||
7 | * |
||
8 | * PHP Version 7.2 |
||
9 | * |
||
10 | * @author Emmanuel Dyan |
||
11 | * |
||
12 | * @copyright 2020 Emmanuel Dyan |
||
13 | * |
||
14 | * @package edyan/neuralyzer |
||
15 | * |
||
16 | * @license GNU General Public License v2.0 |
||
17 | * |
||
18 | * @link https://github.com/edyan/neuralyzer |
||
19 | */ |
||
20 | |||
21 | namespace Edyan\Neuralyzer\Helper\DB; |
||
22 | |||
23 | /** |
||
24 | * Various methods related to MySQL |
||
25 | */ |
||
26 | class MySQL extends AbstractDBHelper |
||
27 | { |
||
28 | /** |
||
29 | 1 | * Send options to be able to load data set |
|
30 | * |
||
31 | 1 | * @return array |
|
32 | */ |
||
33 | public static function getDriverOptions(): array |
||
34 | { |
||
35 | return \defined('\PDO::MYSQL_ATTR_LOCAL_INFILE') ? |
||
36 | 1 | [\PDO::MYSQL_ATTR_LOCAL_INFILE => true] : |
|
37 | []; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Add a custom enum type |
||
42 | * |
||
43 | * @throws \Doctrine\DBAL\DBALException |
||
44 | */ |
||
45 | public function registerCustomTypes(): void |
||
46 | { |
||
47 | // already registered |
||
48 | if (\Doctrine\DBAL\Types\Type::hasType('neuralyzer_enum')) { |
||
49 | return; |
||
50 | } |
||
51 | |||
52 | // Else register |
||
53 | // Manage specific types such as enum |
||
54 | \Doctrine\DBAL\Types\Type::addType( |
||
55 | 'neuralyzer_enum', |
||
56 | 'Edyan\Neuralyzer\Doctrine\Type\Enum' |
||
57 | ); |
||
58 | $platform = $this->conn->getDatabasePlatform(); |
||
59 | $platform->registerDoctrineTypeMapping('enum', 'neuralyzer_enum'); |
||
60 | $platform->registerDoctrineTypeMapping('bit', 'boolean'); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | public function loadData(string $table, string $fname, array $fields, string $mode): string |
||
67 | { |
||
68 | $sql = "LOAD DATA LOCAL INFILE '{$fname}' |
||
69 | 1 | REPLACE INTO TABLE {$table} |
|
70 | FIELDS TERMINATED BY '|' ENCLOSED BY '\"' LINES TERMINATED BY '" . PHP_EOL . "' |
||
71 | 1 | (`" . implode('`, `', $fields) . '`)'; |
|
72 | 1 | // Run the query if asked |
|
73 | 1 | if ($this->pretend === false) { |
|
74 | 1 | $this->conn->query($sql); |
|
0 ignored issues
–
show
|
|||
75 | } |
||
76 | 1 | ||
77 | return $sql; |
||
78 | } |
||
79 | } |
||
80 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.