LOAD DATA INFILE problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
cardin
Forum Newbie
Posts: 1
Joined: Wed Sep 24, 2003 1:45 pm

LOAD DATA INFILE problem

Post by cardin »

I have an update script (included below) to replace the contents of a table with the contents of a text file to record the changes in an alumni database. The TRUNCATE command works perfectly. I always populate the db table with one dummy record before a test. TRUNCATE empties the db table. But the immediately following LOAD DATA INFILE command does nothing.

There appear to be no syntax errors since it always prints the test message. Any clue as to what I'm doing wrong here?

Thanks,

Paul Cardin


<?
// MySQL Settings
$MySqlHostname = "localhost";
$MySqlUsername = "class_admin";
$MySqlPassword = "*****";
$MySqlDatabase = "class_alumni";

/* make connection to database */
/* If no connection made, display error Message */

$dblink=MYSQL_CONNECT($MySqlHostname, $MySqlUsername, $MySqlPassword) OR DIE("Unable to connect to database");

/* Select the database name to be used or else print error message if unsuccessful*/
@mysql_select_db("$MySqlDatabase") or die( "Unable to select database");

mysql_query("TRUNCATE TABLE members");

mysql_query("LOAD DATA INFILE '/home/username/public_html/uploads/classupdate.csv' REPLACE INTO TABLE class_alumni.members FIELDS TERMINATED BY ',' LINES TERMINATED by '\n'");

echo ("End of Program Test.");
?>
User avatar
Leviathan
Forum Commoner
Posts: 36
Joined: Tue Sep 23, 2003 7:00 pm
Location: Waterloo, ON (Currently in Vancouver, BC)

Post by Leviathan »

Why not use an or die(mysql_error()) right after you do your LOAD DATA INFILE query? If MySQL does nothing, that means it doesn't like your query (or some side effect of your query), so you should let MySQL tell you what's wrong. You could also try running the query from within MySQL too.
Post Reply