dongzhuner6981 2018-06-19 09:14
浏览 77
已采纳

只有变量应该通过引用传递 - 当使用LIMIT和bindParam时

I want use LIMIT with bindParam so I build this query:

$app->get('/contact/get_contacts/{contact_number}', function (Request $request, Response $response, array $args)
{
    $query = "SELECT * FROM contact LIMIT :contact_number";
    $sql->bindParam("contact_number", intval($args["contact_number"]), PDO::PARAM_INT);
    $sql->execute();
    $result = $sql->fetchAll();
    return $response->withJson($result);
});

I get this notice:

Only variables should be passed by reference

What I did wrong? I'm using Slim Framework with PDO

  • 写回答

2条回答 默认 最新

  • douzhang5295 2018-06-19 09:18
    关注

    You need to change:

    $sql->bindParam("contact_number", intval($args["contact_number"]), PDO::PARAM_INT);
    

    with,

    $sql->bindParam(":contact_number", $args["contact_number"], PDO::PARAM_INT);
    
    • I have added the missing : before the parameter name.
    • I have removed the intval function call, if you still want to use the function then use it outside of the bindParam function call.

    As per the function definition:

    public bool PDOStatement::bindParam ( mixed $parameter , mixed &$variable [, int $data_type = PDO::PARAM_STR [, int $length [, mixed $driver_options ]]] )
    

    the bound parameter is a variable by reference (&$variable).

    Reading Material

    bindParam

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)