我有一个Mysql查询如下
$query = "UPDATE student_database SET fname='$fname',mname='$mname',lname='$lname',dob='$dob',Age='$age',Sex='$sex',Caste='$caste',dept='$dept', SSC%=$ssc , HSC%=$hsc, ATKTs=$atkt, Last_sem%=$lastsem, Aggregate%=$agg WHERE student_id=$id ; ";
某些列名称中包含“%”符号。 Mysql执行时抛出以下错误
Cannot execute.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 '%=79.6 , HSC%=81.83, ATKTs=5, Last_sem%=52.35, Aggregate%=53.6 WHERE student_id=' at line 1
无法弄清楚问题我尝试过“\”、“#”、“%%”作为转义字符但无法弄清楚。
最佳答案
用反引号括起来,告诉 SQL 它是一个列,这有效吗?
$query = "UPDATE student_database SET fname='$fname',mname='$mname',lname='$lname',dob='$dob',Age='$age',Sex='$sex',Caste='$caste',dept='$dept', `SSC%`=$ssc , `HSC%`=$hsc, ATKTs=$atkt, `Last_sem%`=$lastsem, `Aggregate%`=$agg WHERE student_id=$id ; ";
关于php - 列名称为 '%' 的 Mysql 查询未在 PHP 中执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9316076/