Hello, 
I'm a very new mysql/php user and am trying to use the load data infile
command without luck.  I'd like to replace a table using a text file but
can't get it to work.  I set up a test table with no records using a telnet
console.  I'm trying to write a php page that takes the file on the server
and adds the info into the table.  Here's my code:
 
<?php
 
# Connect to the database
$db = mysql_connect("server", "username","password");
mysql_select_db("dbname",$db);
 
# Delete the current content of the table
$result = mysql_db_query('$sql_id',"DELETE FROM tablename") or die ("Invalid
DELETE query");
 
# Optimize the current table (recover empty space)
$result = mysql_db_query('$sql_id',"OPTIMIZE TABLE tablename") or die
("Invalid OPTIMIZE query");
 
# Load local comma separated, fields enclosed by quotes text database - File
has to be in the same directory of this file $result =
mysql_db_query('$sql_id',"LOAD DATA  INFILE 'file.txt' INTO TABLE tablename
FIELDS TERMINATED BY ',' ENCLOSED BY '\"'") or die ("Invalid DATA LOAD
query");
 
# Get how many records are present in the table now
$result = mysql_db_query('$sql_id',"SELECT * from uploadtable") or die
("Invalid SELECT query"); $rows_count = mysql_num_rows($result);
 
echo "Records: $rows_count"; mysql_free_result($result);
?>
 
I got this from an example given online and the output is the "invalid
delete query".   Even if I delete the first two queries I still get "invalid
data load query"  What's wrong with this code??  Thanks for any help...
Dan
 

Reply via email to