I have a query below. When I try to run it with PHP it errors:

DATABASE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LINES TERMINATED BY '\n'' at line 38 IN

BUT where I copy the echoed query and paste into into my Sequel Pro query editor and run it - works perfectly. Can someone shone some light on this? Frustrating - to say the least.

Don

$csv = "SELECT u.user_id,
                                                        u.first_name AS 
u_first_name,
                                                        u.last_name AS 
u_last_name,
                                                        c.client_id AS 
c_client_id,
                                                        c.first_name AS 
c_first_name,
                                                        c.middle_name AS 
c_middle_name,
                                                        c.last_name AS 
c_last_name,
                                                        c.address AS c_address,
                                                        c.city AS c_city,
                                                        c.state AS c_state,
                                                        c.zip AS c_zip,
                                                        c.dob AS dob_ymd,
                                                        c.phone_home AS 
c_phone_home,
                                                        c.phone_cell AS 
c_phone_cell,
                                                        c.phone_work AS 
c_phone_work,
                                                        c.email AS c_email,
                                                        c.other_contacts AS 
c_other_contacts,
                                                        count(*) as apt_qty
                                                        
                                                        FROM tl_appt apt
                                                        
                                                        JOIN tl_clients c on 
c.client_id = apt.client_id
                                                        JOIN tl_rooms r on 
r.room_id = apt.room_id
                                                        JOIN tl_users u on 
u.user_id = apt.user_id
                                                        
                                                        WHERE
                                                        
                                                                apt.time_start between 
'".$sd."' and '".$ed."'
                                                                ".$where_sql."
                                                                
                                                        GROUP BY u.user_id, 
c.client_id
                                                        having count(*) ".$aoper." 
".$aqty."
                                                        
                                                        ORDER BY u.first_name, 
u.last_name, c.last_name, c.first_name
                                                        INTO OUTFILE 
'/tmp/".$csv_file.".csv'
                                                        FIELDS TERMINATED BY ','
                                                        ENCLOSED BY '\"';
                                                        LINES TERMINATED BY 
'"."\\n"."'";

                                echo $csv;
                                
                                
                                
                                $csv_query = $db->db_query($csv);

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to