duanji1610 2012-08-05 14:06
浏览 56
已采纳

php - PDO:bindParam令牌语法问题

Is there a solution for this error? Is it happening because of the mySQL time format in the query?

SQL Error
Error:SQLSTATE[HY093]: Invalid parameter number: number of bound variables 
does not match number of tokens 

Array
(
    [:service_user_id] => 90
    [:week_beginning] => 2012-08-06
    [:week_ending] => 2012-08-12
)
Backtrace:C:\wamp\www\Sitetest_9.6.12\public_html\main\ajax\timetable_grid_load.php at line 45 

This is the PHP using php-pdo-wrapper-class:

$bind = array(
    ":service_user_id" =>  $service_user_id,
    ":week_beginning" => $week_beginning,
    ":week_ending" => $week_ending,
);


$query = "SELECT 
    id AS sessID,
    session_day as sessDay,
    session_type_id,
    provider_id,
    description,
    TIME_FORMAT(start_time, '%H:%i') as start_time,
    TIME_FORMAT(finish_time, '%H:%i') as finish_time,
    start_date,
    finish_date,
    (SELECT absence FROM attendance WHERE sessID = session_id AND absence_date = DATE_ADD(':week_beginning', INTERVAL sessDay-1 DAY)) AS attendance
    FROM
    sessions
    WHERE
    service_user_id = :service_user_id AND
    start_date <= ':week_ending' AND
    (finish_date >= ':week_beginning' OR
    finish_date IS NULL OR 
    finish_date=0)
    ORDER BY session_day ASC";      

$result= $db->run($query,$bind);
return $result;
  • 写回答

1条回答 默认 最新

  • douzhang5121 2012-08-05 14:14
    关注

    Do not use single quotes to delimit parameters in a prepared statement. It's not necessary (that's the whole point of having prepared statements in the first place).

        ...
    WHERE
        service_user_id = :service_user_id AND
        start_date <= :week_ending AND
        (finish_date >= :week_beginning OR
        finish_date IS NULL OR 
        ...
    

    Hint: start_date <= ':week_ending' translates to less than or equal to the literal string ":week_ending".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TMC2209串口模式下读取不到寄存器的值串口助手蓝色字体是发过去的消息,绿色字体是收到的消息,第二行发送读取寄存器的指令但是没有读取到寄存器的值串口助手如下图:接线如下图,如何解决?
  • ¥15 高通安卓11提取完整线刷包软件,或者优博讯dt50顺丰刷机包
  • ¥20 C,有个译码器,换了信道就跑不出原来数据
  • ¥15 MIMIC数据库安装问题
  • ¥60 基于JTag协议开发Fpga下载器上位机,哪位大🐂有偿指导?
  • ¥20 全书网Java爬取数据
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏
  • ¥15 STM32串口接收问题