这是SQL:
TRUNCATE TABLE `dc_path`;
INSERT INTO dc_path (coords) VALUES('(40.64406436923055, -8.638539251709062)');
INSERT INTO dc_path (coords) VALUES('(40.62791121610622, -8.615193304443437)');
INSERT INTO dc_path (coords) VALUES('(40.62895347295352, -8.6625718444825)');
如果我尝试在phpmyadmin上执行该查询,则效果很好,但是通过php,则会出现此错误:
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 'INSERT INTO dc_path (coords) VALUES('(40.64406436923055, -8.638539251709062)');I' at line 1
我尝试了很多事情,但无法解决!
提前致谢。
编辑:
的PHP
function insertPath($coords){
$conn = connectDB();
$coords = explode(";",$coords);
$sql = "";
$sql = "TRUNCATE TABLE `dc_path`; ";
for($i=0;$i<count($coords)-1;$i++){
$sql .= "INSERT INTO dc_path (coords) VALUES('".$coords[$i]."');";
}
echo $sql;
$query = mysql_query($sql, $conn) or die(mysql_error());
closeDB($conn);
return true;
}
$ coords变量包含类似以下值的内容:
(40.638854101691635, -8.6515855163575);(40.629474595277166, -8.63235944213875);
最佳答案
function insertPath($coords){
$conn = connectDB();
$coords = explode(";",$coords);
mysql_query("TRUNCATE TABLE `dc_path`", $conn);
for($i=0;$i<count($coords)-1;$i++){
mysql_query("INSERT INTO dc_path (coords) VALUES('".$coords[$i]."')", $conn);
}
closeDB($conn);
return true;
}
关于php - 奇怪的行为PHP与MySQL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10182575/