Skip to content

Commit eac330f

Browse files
jefvhalavbdr
authored andcommitted
Update MysqliDb.php (ThingEngineer#655)
* Update MysqliDb.php Added option for LOAD DATA LOCAL * Update readme.
1 parent 97f20c2 commit eac330f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

MysqliDb.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ public function loadData($importTable, $importFile, $importSettings = null)
10421042

10431043
// Define the default values
10441044
// We will merge it later
1045-
$settings = Array("fieldChar" => ';', "lineChar" => PHP_EOL, "linesToIgnore" => 1);
1045+
$settings = Array("fieldChar" => ';', "lineChar" => PHP_EOL, "linesToIgnore" => 1);
10461046

10471047
// Check the import settings
10481048
if(gettype($importSettings) == "array") {
@@ -1056,9 +1056,12 @@ public function loadData($importTable, $importFile, $importSettings = null)
10561056
// Add 1 more slash to every slash so maria will interpret it as a path
10571057
$importFile = str_replace("\\", "\\\\", $importFile);
10581058

1059+
// Switch between LOAD DATA and LOAD DATA LOCAL
1060+
$loadDataLocal = isset($settings["loadDataLocal"]) ? 'LOCAL' : '';
1061+
10591062
// Build SQL Syntax
1060-
$sqlSyntax = sprintf('LOAD DATA INFILE \'%s\' INTO TABLE %s',
1061-
$importFile, $table);
1063+
$sqlSyntax = sprintf('LOAD DATA %s INFILE \'%s\' INTO TABLE %s',
1064+
$loadDataLocal, $importFile, $table);
10621065

10631066
// FIELDS
10641067
$sqlSyntax .= sprintf(' FIELDS TERMINATED BY \'%s\'', $settings["fieldChar"]);

readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ Attach them using
301301
```php
302302
$options = Array("fieldChar" => ';', "lineChar" => '\r\n', "linesToIgnore" => 1);
303303
$db->loadData("users", "/home/john/file.csv", $options);
304+
// LOAD DATA ...
305+
```
306+
307+
You can specify to **use LOCAL DATA** instead of **DATA**:
308+
```php
309+
$options = Array("fieldChar" => ';', "lineChar" => '\r\n', "linesToIgnore" => 1, "loadDataLocal" => true);
310+
$db->loadData("users", "/home/john/file.csv", $options);
311+
// LOAD DATA LOCAL ...
304312
```
305313

306314
### Insert XML

0 commit comments

Comments
 (0)