douzhan1963 2015-07-08 00:51
浏览 83

使用select语句的MySQL语法错误

Hi can you please help me in this, I don't know where my error is. here is my code:

    $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'];
     }

and the error while I am executing it by php:

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
  • 写回答

1条回答 默认 最新

  • ds211107 2015-07-08 00:56
    关注

    Your first mysql_query is returning a resource (a resultset) and assigning it to $capacitance. When you execute mysql_query again in the next line, $capacitance, a resource, is turned into a string - "Resource #4", likely - which is not a proper SQL.

    Also note that "Bobby Tables doesn't go to my school" is not necessarily true: escape your strings properly.

    $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 ...
    
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数