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