Conditions | 4 |
Paths | 4 |
Total Lines | 23 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 7 |
CRAP Score | 4.432 |
Changes | 0 |
1 | <?php |
||
44 | 2 | public function loadData( |
|
45 | string $table, |
||
46 | string $filename, |
||
47 | array $fields, |
||
48 | string $mode |
||
49 | ): string { |
||
50 | 2 | if (substr(gethostbyname($this->conn->getHost()), 0, 3) !== '127') { |
|
51 | 1 | throw new NeuralizerException('SQL Server must be on the same host than PHP'); |
|
52 | } |
||
53 | |||
54 | 1 | $sql ="BULK INSERT {$table} FROM '{$filename}' WITH ( |
|
55 | 1 | FIELDTERMINATOR = '|', DATAFILETYPE = 'widechar', ROWTERMINATOR = '" . PHP_EOL . "' |
|
56 | )"; |
||
57 | |||
58 | 1 | if ($this->pretend === false) { |
|
59 | if ($mode === 'update') { |
||
60 | $this->conn->query("TRUNCATE TABLE {$table}"); |
||
61 | } |
||
62 | |||
63 | $this->conn->query($sql); |
||
64 | } |
||
65 | |||
66 | 1 | return $sql; |
|
67 | } |
||
69 |