Re: Load Data infile

From: Date: Fri, 14 May 2004 01:03:01 +0000
Subject: Re: Load Data infile
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-186186@lists.php.net to get a copy of this message
Juan Pablo Herrera wrote:
[snip] I need do load data infile in mysql: $query_string2 = "LOAD DATA INFILE '/var/www/xls/test' REPLACE INTO TABLE test FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\\' LINES TERMINATED BY '\n'";$query_db_string2 = mysql_query($query_string2); But not realize nothing with execution the script. [/snip] have you checked mysql_error() ?
yes, You have an error in your SQL syntax near ''' at line 2 but i change '\"' and not work.
The problem is PHP parses the string before it's passed to MySQL. Since you're using double quotes "ESCAPED BY '\\' LINES" is parsed to "ESCAPED BY '\' LINES" by PHP and then sent to MySQL, which causes an error. Two solutions: 'ESCAPED BY \'\\\' LINES' (use single quotes) or "ESCAPED BY '\\\\' LINES" -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.general (#186186) next »