Reputation: 1221
I am trying to use php to put SQL results into a .csv file where the file name will be the current date and time.
The search query below works if I insert a unique filename manually, but when I try to concatenate the $date
variable as below, I get a mysql syntax error in terminal.
$date = date('Y-m-d h:i:s')
$query_text = "SELECT Code FROM Country WHERE HeadOfState = 'Big Bird' INTO OUTFILE '/tmp/' . $date . '.csv'";
$result = mysql_query($query_text);
This seems logical to me from the context of PHP, but SQL doesn't seem to like it.
Any help is greatly appreciated. Thanks.
Upvotes: 1
Views: 2441
Reputation: 2522
break out of your code with double quotes.
$query_text = "SELECT Code FROM Country WHERE HeadOfState = 'Big Bird' INTO OUTFILE '/tmp/" . $date . ".csv'";
Upvotes: 1