dongsuoxi1790 2012-09-12 16:02
浏览 71
已采纳

PDO抛出错误

I'm going crazy looking for the error in the following PDO SELECT statement:

$get_allocation_id = "
  SELECT id
  FROM form1_group_info 
  WHERE
   group_name=:group_name, 
   group_leaders=:group_leaders, 
   soas_short_cd=:soas_short_cd, 
   phone_number=:phone_number, 
   email=:email 
  LIMIT 1";
$alloc_id_stmt = $dbh->prepare($get_allocation_id);
$alloc_id_stmt->bindParam(":group_name", $params['group_name']);
$alloc_id_stmt->bindParam(":date_submitted", $params['date_submitted']);
$alloc_id_stmt->bindParam(":group_leaders", $params['group_leaders']);
$alloc_id_stmt->bindParam(":soas_short_cd", $params['soas_short_cd']);
$alloc_id_stmt->bindParam(":phone_number", $params['phone_number']);
$alloc_id_stmt->bindParam(":email", $params['email']);
$alloc_id_stmt->execute();

The above code is in a PHP file that is called by an ajax request which supplies $params.

Any suggestions are much appreciated.

  • 写回答

2条回答 默认 最新

  • duanjunao9348 2012-09-12 16:04
    关注

    Your SQL syntax is invalid; WHERE clause conditions must separated by logical AND (or OR, but we assume you mean to sue AND in this case), but you have separated them by commas:

      SELECT id
      FROM form1_group_info 
      WHERE
       group_name=:group_name
       /* Insert logical AND */
       AND group_leaders=:group_leaders 
       AND soas_short_cd=:soas_short_cd 
       AND phone_number=:phone_number
       AND email=:email 
      LIMIT 1;
    

    As mentioned above, you are also binding a parameter which is not used in your query. Perhaps you mean:

      SELECT id
      FROM form1_group_info 
      WHERE
       group_name=:group_name 
       AND group_leaders=:group_leaders 
       AND soas_short_cd=:soas_short_cd 
       AND phone_number=:phone_number
       AND email=:email
       /* forgot this one... */
       AND date_submitted=:date_submitted
      LIMIT 1;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog