嗨,你可以帮助我,我不知道我的错误在哪里。 这是我的代码:
$capacitance =@mysql_query ("SELECT DISTINCT wwpn, SUBSTR(val, 1, LENGTH(val) / 2) as capacitor,
SUBSTR(val, LENGTH(val) / 2+1) as capasitance
FROM bom_csv where boardnumber ='$board' and qty<>'' and qty !='qty'");
@mysql_query($capacitance,$connect)or die("Failed to execute query:<br />" . mysql_error(). "<br />" . mysql_errno());
while($row = mysql_fetch_array($capacitance))
{
$capacitor = $row['capacitor'];
$capacitance =$row['capasitance'];
$adi_pn = $row['wwpn'];
}
和我在执行它时的错误:
Failed to execute query:
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 'Resource id #4' at line 1
1064
答案 0 :(得分:2)
您的第一个mysql_query
正在返回资源(结果集)并将其分配给$capacitance
。当您在下一行mysql_query
再次执行$capacitance
时,资源会变成字符串 - "Resource #4"
,可能是 - 这不是正确的SQL。
另请注意,“Bobby Tables没有去我的学校”并不一定如此:正确地逃避你的字符串。
$capacitance = @mysql_query ("SELECT DISTINCT wwpn, SUBSTR(val, 1, LENGTH(val) / 2) as capacitor,
SUBSTR(val, LENGTH(val) / 2+1) as capasitance
FROM bom_csv where boardnumber ='" . mysql_real_escape_string($board) . "' and qty<>'' and qty !='qty'", $connect)
or die("Failed to execute query:<br />" . mysql_error(). "<br />" . mysql_errno());
while ...