需要第二只眼睛来调试查询

发布于 2024-10-01 14:01:46 字数 3716 浏览 0 评论 0原文

这也许是一个特殊的问题,我确实需要第二只眼睛。我正在我的 PHP 脚本中运行以下查询,但在查找查询中的错误行时遇到问题。当我回显 $query 时,我看到输出有效,但查询给出了错误,并在输出末尾显示错误:

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 ''),('1','$GPRMC','040837.002','A','60.15465','N','24.7436' 附近使用的正确语法,'E','0.5',1970,01,01'' 在第 1 行

运行以下查询:

query = "INSERT INTO rmc_raw_data
           (device_id, nmea, rmc_time, signal, latitude, north, longitude, east, speed, track_angle, rmc_date, magnetic_variation, west,check_sum) 
         VALUES";
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
  $numlines++;

  $myDay=substr($data[9], 0,2);
  $myMonth=substr($data[9], 2,2);
  $myYear=substr($data[9], 4,2);            

  $rmc_date = convertToNiceDate($myDay, $myMonth, 2000+$myYear);

  $longitude = convertToDegrees($data[6]);
  $latitude  = convertToDegrees($data[4]);

  $query .= "('$data[0]','$data[1]','$data[2]','$data[3]','$latitude','$data[5]','$longitude','$data[7]','$data[8]',$rmc_date','$data[10]','$data[11]','$data[12]'),";
}

$query = substr($query, 0,-1);

echo $query;
mysql_query($query) or die(mysql_error());

该查询从文本文件导入和操作数据,该文件具有以下以逗号分隔的数据行示例:

//input data
1,$GPRMC,080323.460,A,6013.45368,N,02445.28396,E,21.6,134.0,070610,6.9,W,A*2A
1,$GPRMC,080327.000,A,6013.44424,N,02445.31214,E,9.0,135.2,070610,6.9,W,A*1E
1,$GPRMC,132305.000,V,,,,,,,070610,,,N*4B
1,$GPRMC,132320.000,V,,,,,,,070610,,,N*4C
1,$GPRMC,132335.000,V,,,,,,,070610,,,N*48
1,$GPRMC,132350.000,V,,,,,,,070610,,,N*4B
1,$GPRMC,134841.000,V,,,,,,,070610,,,N*46
1,$GPRMC,134856.000,A,6009.32417,N,02444.63687,E,1.7,124.8,070610,6.9,W,A*1A
1,$GPRMC,134911.000,A,6009.32239,N,02444.63356,E,,,070610,,,A*64
1,$GPRMC,134927.000,V,,,,,,,070610,,,N*47
1,$GPRMC,155411.405,V,,,,,,,070610,,,N*49
-------

我正在 正如我测试看到的那样,查询将结果输出到屏幕,它还在输出的以下点处给出了错误,即它终止的位置:

//output data to be inserted
        ('1','$GPRMC','142346.000','A','60.15675','N','24.74189','E','14.1',1970,01,01','290610','6.9','W'),    ('1','$GPRMC','142349.000','A','60.15656','N','24.74203','E','13.5',1970,01,01','290610','6.9','W'),    ('1','$GPRMC','142402.000','A','60.15565','N','24.74287','E','13.2',1970,01,01','290610','6.9','W'),    ('1','$GPRMC','142411.000','A','60.1551','N','24.74347','E','7.3',1970,01,01','290610','6.9','W'),    ('1','$GPRMC','142414.000','A','60.15507','N','24.74346','E','',1970,01,01','290610','',''),    ('1','$GPRMC','142417.000','A','60.15514','N','24.74358','E','6.4',1970,01,01','290610','6.9','W'),    ('1','$GPRMC','142423.000','A','60.15524','N','24.74371','E','',1970,01,01','290610','',''),    ('1','$GPRMC','142435.000','A','60.15512','N','24.74365','E','',1970,01,01','290610','',''),
('1','$GPRMC','142447.000','V','0','','0','','',1970,01,01','290610','',''),
('1','$GPRMC','142459.000','V','0','','0','','',1970,01,01','290610','',''),
('1','$GPRMC','062917.637','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','062932.000','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','063206.392','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','080238.101','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','080253.000','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','080305.000','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','080308.000','V','0','','0','','',1970,01,01','070610','','')


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 '','070610','6.9','W'),('1','$GPRMC','080327.000','A','60.22407','N','24.7552','E' at line 1

我一直在努力跟踪错误,但没有解决方案,我已经通过类似的结果获得了相同的结果。文件的性质毫无疑虑但这让我抓狂。

This perhaps is a peculiar problem and I do need a second eye. I am running th following query in my PHP script but am having problem finding the errring line in my query. When I echo the $query, I see the output which valid but the query gives and error at the end of the output saying:

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 ''),('1','$GPRMC','040837.002','A','60.15465','N','24.7436','E','0.5',1970,01,01'' at line 1

I am running the following query:

query = "INSERT INTO rmc_raw_data
           (device_id, nmea, rmc_time, signal, latitude, north, longitude, east, speed, track_angle, rmc_date, magnetic_variation, west,check_sum) 
         VALUES";
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
  $numlines++;

  $myDay=substr($data[9], 0,2);
  $myMonth=substr($data[9], 2,2);
  $myYear=substr($data[9], 4,2);            

  $rmc_date = convertToNiceDate($myDay, $myMonth, 2000+$myYear);

  $longitude = convertToDegrees($data[6]);
  $latitude  = convertToDegrees($data[4]);

  $query .= "('$data[0]','$data[1]','$data[2]','$data[3]','$latitude','$data[5]','$longitude','$data[7]','$data[8]',$rmc_date','$data[10]','$data[11]','$data[12]'),";
}

$query = substr($query, 0,-1);

echo $query;
mysql_query($query) or die(mysql_error());

The query imports and manipulates data from a text file which has the following sample of data lines which are comma delimited:

//input data
1,$GPRMC,080323.460,A,6013.45368,N,02445.28396,E,21.6,134.0,070610,6.9,W,A*2A
1,$GPRMC,080327.000,A,6013.44424,N,02445.31214,E,9.0,135.2,070610,6.9,W,A*1E
1,$GPRMC,132305.000,V,,,,,,,070610,,,N*4B
1,$GPRMC,132320.000,V,,,,,,,070610,,,N*4C
1,$GPRMC,132335.000,V,,,,,,,070610,,,N*48
1,$GPRMC,132350.000,V,,,,,,,070610,,,N*4B
1,$GPRMC,134841.000,V,,,,,,,070610,,,N*46
1,$GPRMC,134856.000,A,6009.32417,N,02444.63687,E,1.7,124.8,070610,6.9,W,A*1A
1,$GPRMC,134911.000,A,6009.32239,N,02444.63356,E,,,070610,,,A*64
1,$GPRMC,134927.000,V,,,,,,,070610,,,N*47
1,$GPRMC,155411.405,V,,,,,,,070610,,,N*49
-------

While the query outputed the result to screen as I tested to see, it also gave an error at the following point of the output i.e where it terminated:

//output data to be inserted
        ('1','$GPRMC','142346.000','A','60.15675','N','24.74189','E','14.1',1970,01,01','290610','6.9','W'),    ('1','$GPRMC','142349.000','A','60.15656','N','24.74203','E','13.5',1970,01,01','290610','6.9','W'),    ('1','$GPRMC','142402.000','A','60.15565','N','24.74287','E','13.2',1970,01,01','290610','6.9','W'),    ('1','$GPRMC','142411.000','A','60.1551','N','24.74347','E','7.3',1970,01,01','290610','6.9','W'),    ('1','$GPRMC','142414.000','A','60.15507','N','24.74346','E','',1970,01,01','290610','',''),    ('1','$GPRMC','142417.000','A','60.15514','N','24.74358','E','6.4',1970,01,01','290610','6.9','W'),    ('1','$GPRMC','142423.000','A','60.15524','N','24.74371','E','',1970,01,01','290610','',''),    ('1','$GPRMC','142435.000','A','60.15512','N','24.74365','E','',1970,01,01','290610','',''),
('1','$GPRMC','142447.000','V','0','','0','','',1970,01,01','290610','',''),
('1','$GPRMC','142459.000','V','0','','0','','',1970,01,01','290610','',''),
('1','$GPRMC','062917.637','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','062932.000','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','063206.392','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','080238.101','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','080253.000','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','080305.000','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','080308.000','V','0','','0','','',1970,01,01','070610','','')


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 '','070610','6.9','W'),('1','$GPRMC','080327.000','A','60.22407','N','24.7552','E' at line 1

I have been working to trace the error but no solution. I had achieved same result with a similar nature of file without qualms. But this is getting me nuts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑忘罢 2024-10-08 14:01:46

$rmc_date 未正确引用。

$rmc_date is not quoted properly.

就像说晚安 2024-10-08 14:01:46

“$rmc_date”附近缺少引号

missing quote near "$rmc_date"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文