Page 1 of 1

Load Data into MySQL

Posted: Tue Aug 31, 2004 9:04 pm
by AliasBDI
I am trying to load data from a comma delimited TXT file into a MySQL database (version MySQL 4.0.17-nt). Here is my code:

Code: Select all

<?php
## Connect to a local database server (or die) ##
$dbH = mysql_connect('localhost', '********', '*********') or die('Could not connect to MySQL server.<br>' . mysql_error());

## Select the database to insert to ##
mysql_select_db('econtrol_canaanloanscom') or die('Could not select database<br>' . mysql_error());

## CSV file to read in ##
$CSVFile = 'data.txt';

mysql_query('LOAD DATA LOCAL INFILE "data.txt" INTO TABLE var_zipcodes FIELDS TERMINATED BY "," LINES TERMINATED BY "\\r\\n";') or die('Error loading data file.<br>' . mysql_error());

## Close database connection when finished ##
mysql_close($dbH);
?>
The page returns this:
Error loading data file.
The used command is not allowed with this MySQL version
Any ideas on how to resolve this?


feyd | stripped user/pass

Posted: Wed Sep 01, 2004 9:39 am
by Draco_03
Get your poassword and username out of your code AliasBDI..

Ps : I think you should use only one slash

Code: Select all

TERMINATED BY "\\r\\n"
should be

Code: Select all

TERMINATED BY "\r\n"
(it's a wild guess i m not sure)

Posted: Wed Sep 01, 2004 1:00 pm
by AliasBDI
Same result. Thanks though.

Posted: Wed Sep 08, 2004 12:30 am
by litebearer
As an altenative to 'Load Data .." you could always read the file contents into an array. Then loop thru the array and "explode" each line. At which point you could insert the 'fields'/data into the table.

Lite...

Posted: Tue Sep 14, 2004 3:34 pm
by sulen
Why dont you use LOAD DATA INFILE instead ........... you must have already tried it but maybe that could work............. :!: