forked from catch-design/php-js-dev-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSVImporter.php
33 lines (31 loc) · 944 Bytes
/
CSVImporter.php
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
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/catchnz_test/db.php');
// helper class to export CSV into mysql ...
/**
* CSV Importer class
*/
class CSVImporter extends db{
function __construct(){
parent::__construct();
}
// imports the csv file into given table ...
/**
* imports the given csv file into given table
* @param {?string} file - file path o CSV
* @param {?string} tableName - name of table into which data to be imported
*/
public function importCSV($file, $tableName) {
if($this->isTableExists($tableName)) {
mysql_query( '
LOAD DATA LOCAL INFILE "'.$file.'"
INTO TABLE `' . $tableName . '`
FIELDS TERMINATED by \',\'
LINES TERMINATED BY \'\n\'
IGNORE 1 LINES
', $this->conn)or die(mysql_error());
} else {
die("Internal Error in imporing CSV...!!");
}
}
}
?>