gpt4 book ai didi

php - token 声明时 PDO 中的参数无效

转载 作者:太空宇宙 更新时间:2023-11-03 10:50:56 26 4
gpt4 key购买 nike

我有正确执行的查询:

$query = $handler->prepare("SELECT * FROM pm WHERE ((user1 = $userid AND user1read = 'no') OR (user2 = $userid AND user2read = 'no') AND id2 = '1')");
$query->execute();

当我尝试声明标记时,它抛出一个 Invalid parameter number' fatal error 。这是引发错误的代码:

$query = $handler->prepare("SELECT * FROM pm WHERE ((user1 = :userid AND user1read = 'no') OR (user2 = :userid AND user2read = 'no') AND id2 = '1')");
$query->execute(array(
'userid' => $userid
));

我正在尝试从 sql 迁移到 PDO。这里是否有一些我遗漏的 sql 残余?

最佳答案

您不能在准备好的语句中两次使用同名的命名参数标记

来源:http://php.net/manual/de/pdo.prepare.php

尝试:

$query = $handler->prepare("SELECT * FROM pm WHERE ((user1 = :userid AND user1read = 'no')     OR (user2 = :userid2 AND user2read = 'no') AND id2 = '1')");
$query->execute(array(
'userid' => $userid,
'userid2' => $userid
));

关于php - token 声明时 PDO 中的参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25168592/

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