forked from jhalak/big-data-performance-testing-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert-into-database-from-file.php
More file actions
39 lines (31 loc) · 887 Bytes
/
insert-into-database-from-file.php
File metadata and controls
39 lines (31 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
/**
* insert-into-database-from-file.php
*
* @author: Onirudda Odikare Jhalak <jhalak1983@gmail.com>
* @created on: 6/10/18
*/
require_once "vendor/autoload.php";
require_once "database.php";
use Illuminate\Database\Capsule\Manager as Database;
if (count($argv) < 2) {
print "Argument missing: " . PHP_EOL;
print "Example: php insert-into-database-from-file.php [fileName]" . PHP_EOL;
exit();
}
$filename = $argv[1];
echo "Writing records in students table from file ... " . PHP_EOL;
try {
TimeTracker::start();
$query = 'LOAD DATA LOCAL INFILE \'' . $filename . '\'
INTO TABLE students
CHARACTER SET UTF8
FIELDS TERMINATED BY \'\t\'
ENCLOSED BY \'\\"\'
LINES TERMINATED BY \'\n\'';
Database::connection()->getPdo()->exec(Database::raw($query));
TimeTracker::end();
TimeTracker::showTimeDiff();
} catch (Exception $e) {
echo $e->getMessage();
}