Montagna, Dan wrote:

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.net", "username","password");
mysql_select_db("elasticnature",$db);
# Delete the current content of the table
$result = mysql_db_query('$sql_id',"DELETE FROM tablename") or die ("Invalid
DELETE query");

do you have a table called 'tablename' ? i guess not!


# 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". What's wrong with this code?? Thanks for any help...


--
Sebastian Mendel

www.sebastianmendel.de
www.tekkno4u.de
www.nofetish.com


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to