Setting an error limit while updating table based conditions php
I have got a question. I have not done this before and am not sure if that is how it should be done.
I have a mySQL query which is working correctly. I use it in phpMyAdmin query editor whenever I want to do an update. However, I want to make life easier for a user by putting the query in a php script so the user can just click a link and the task is done.
I did th开发者_如何学编程e following:
$sql = " SET @error_limit = 10E-6;
UPDATE (
SELECT r.rmc_id, 'rmc_raw_data' src, r.rmc_time, r.rmc_date, r.latitude, r.longitude,
IF(s.server_id IS NULL, 'Mobile', 'Both') c FROM rmc_raw_data r
LEFT JOIN server_log_data s
ON r.rmc_time = s.server_rmc_time AND r.rmc_date = s.server_rmc_date AND ABS(r.latitude - s.server_latitude)/r.latitude < @error_limit AND ABS(r.longitude - s.server_longitude)/r.longitude < @error_limit
UNION SELECT s.server_id, 'server_log_data' src, s.server_rmc_time, s.server_rmc_date, s.server_latitude, s.server_longitude, IF(r.rmc_id IS NULL, 'Server', 'Both') c FROM rmc_raw_data r RIGHT JOIN server_log_data s ON r.rmc_time = s.server_rmc_time AND r.rmc_date = s.server_rmc_date AND ABS(r.latitude - s.server_latitude)/r.latitude < @error_limit AND ABS(r.longitude - s.server_longitude)/r.longitude < @error_limit ) t LEFT JOIN rmc_raw_data r1 ON r1.rmc_id = t.rmc_id AND t.src = 'rmc_raw_data' LEFT JOIN server_log_data s1 ON s1.server_id = t.rmc_id AND t.src = 'server_log_data' SET r1.data_source = c, s1.data_source = c;"; $result = mysql_query($sql, $link); if($result){ echo " Query executed successfully"; ... ...
So I put the whole thing my php script but got a mysql 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 'UPDATE ( SELECT r.rmc_id, 'rmc_raw_data' src, r.rmc_time, r.rmc_date, r.latit' at line 1
Could someone suggest what am doing wrong here? It is my thinking that the error limit I have set on the first line of the query is responsible but I had thought that one could put his working query in the mysql_query() and it works.
'rmc_raw_data' src,
this quotes will break the query ???
精彩评论