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 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献