Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql statement not working

Status
Not open for further replies.

stasJohn

Programmer
May 6, 2004
155
US
I have a php script. I'm trying to set it up so it backs up a database table to the server.

in the php, I call...
Code:
SELECT * INTO OUTFILE '".$bck_dir."/mdb-backup.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n' FROM members

I get the following error...
1064: You have an error in your SQL syntax near '' FROM members' at line 2


If I run the sql statement in MySQL CC on my linux box it works fine! Help anyone.

mysql and php are on a linux box. Regular Select statements work fine.
 
I don't know if this means anything, but I noticed the
Code:
LINES TERMINATED BY '\r\n'
was not escaped properly.
So modified the statement to...
Code:
SELECT * INTO OUTFILE '".$bck_dir."/mdb-backup.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\\' LINES TERMINATED BY '\\r\\n' FROM members
which know yields the error...
1064: You have an error in your SQL syntax near '\r\n' FROM members' at line 1


please help!
 
mysqldump is a system command. How do I invoke it within a php script??
 
Try:
[tt]
$sql=
"SELECT * ".
"INTO OUTFILE '".$bck_dir."/mdb-backup.csv'".
" FIELDS TERMINATED BY ','".
" OPTIONALLY ENCLOSED BY '\"'".
" ESCAPED BY '\\\\'".
" LINES TERMINATED BY '\\r\\n' ".
"FROM members";
[/tt]


-----
ALTER world DROP injustice, ADD peace;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top