LOAD DATA INFILE
PHP Code:
<?php
define ( 'DB_HOST', 'localhost:3306' ); // should not need to change
define ( 'DB_USER', 'user' ); // enter the user name for this database
define ( 'DB_PASS', 'pass' ); // enter the password for this database
define ( 'DB_NAME', 'my_db' ); // enter the database name you are connecting to
define ( 'DB_TABLE', 'my_table' ); // enter the NAME of the database TABLE to INSERT data into
define ( 'DBF_CSVP', './path_to/csv.txt' ); // enter the PATH and NAME of the CSV FILE to IMPORT
mysql_connect ( DB_HOST, DB_USER, DB_PASS ) or die ( 'Connection Error: ' . mysql_error () );
mysql_select_db ( DB_NAME ) or die ( 'Select DB (' . DB_NAME . ') Error: ' . mysql_error () );
/* change or add any (terminated, enclosed or escaped) option that you need */
$query = "LOAD DATA INFILE '" . DBF_CSVP . "' INTO TABLE " . DB_TABLE . " FIELDS TERMINATED BY '\\t\\t' OPTIONALLY ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\\r\\n'";
mysql_query ( $query );
?>
Bookmarks