gpt4 book ai didi

php - 仅应通过引用传递变量 - 当将 LIMIT 与 bindParam 一起使用时

转载 作者:行者123 更新时间:2023-11-30 21:42:32 25 4
gpt4 key购买 nike

我想将 LIMITbindParam 一起使用,所以我构建了这个查询:

$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);
});

我收到这条通知:

Only variables should be passed by reference

我做错了什么?我正在使用 Slim FrameworkPDO

最佳答案

你需要改变:

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

与,

$sql->bindParam(":contact_number", $args["contact_number"], PDO::PARAM_INT);
  • 我在参数名称前添加了缺少的 :
  • 我已经删除了 intval 函数调用,如果您仍想使用该函数,请在 bindParam 函数调用之外使用它。

根据函数定义:

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

绑定(bind)参数是一个variable by reference (&$变量)。

阅读 Material

bindParam

关于php - 仅应通过引用传递变量 - 当将 LIMIT 与 bindParam 一起使用时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50924652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com