我的 PDO 执行函数出错

发布于 2024-10-08 18:09:31 字数 1478 浏览 2 评论 0 原文

我有以下查询:

SELECT case when card_type='A'  then name else  CONCAT_WS(' ',firstname,lastname)  end 
                     as cname ,cardid,card_type,isDeck,userid_from,status,cards.gibid,message ,userid_to,description,tagline,gibs.preview_thumb
                    ,case when  userid_from=userid_to then 'my card ' else 'other 'end as owner 
            FROM cards LEFT JOIN gibs ON gibs.gibid=cards.gibid
                left join users on users.userid=cards.userid_from
            WHERE userid_to=? and cards.deleted='N'  and (case when card_type='A'  then name else  CONCAT_WS(' ',firstname,lastname)  end)  like '%?%'
            order by status,card_type desc,owner,cname,isDeck desc

执行函数中传递的数组是:

Array
(
    [0] => 1
    [1] => rahul
)

它给了我错误..

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /var/www/ryapi/Db.php on line 176

Fatal error: Uncaught exception 'PDOException' with message 'Database error [HY093]: , driver error code is ' in /var/www/ryapi/Db.php:179
Stack trace:
#0 /var/www/ryapi/Db.php(93): Db::_query('SELECT case whe...', Array)
#1 /var/www/ryapi/card.php(152): Db::getResult('SELECT case whe...', Array)
#2 /var/www/ryapi/index.php(103): Card->getcardlist('1', '', 'rahul')
#3 {main}
  thrown in /var/www/ryapi/Db.php on line 179

为什么会出现此错误,请提出建议。

I have the following query:

SELECT case when card_type='A'  then name else  CONCAT_WS(' ',firstname,lastname)  end 
                     as cname ,cardid,card_type,isDeck,userid_from,status,cards.gibid,message ,userid_to,description,tagline,gibs.preview_thumb
                    ,case when  userid_from=userid_to then 'my card ' else 'other 'end as owner 
            FROM cards LEFT JOIN gibs ON gibs.gibid=cards.gibid
                left join users on users.userid=cards.userid_from
            WHERE userid_to=? and cards.deleted='N'  and (case when card_type='A'  then name else  CONCAT_WS(' ',firstname,lastname)  end)  like '%?%'
            order by status,card_type desc,owner,cname,isDeck desc

and array passed in execute function is :

Array
(
    [0] => 1
    [1] => rahul
)

it is giving me error ..

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /var/www/ryapi/Db.php on line 176

Fatal error: Uncaught exception 'PDOException' with message 'Database error [HY093]: , driver error code is ' in /var/www/ryapi/Db.php:179
Stack trace:
#0 /var/www/ryapi/Db.php(93): Db::_query('SELECT case whe...', Array)
#1 /var/www/ryapi/card.php(152): Db::getResult('SELECT case whe...', Array)
#2 /var/www/ryapi/index.php(103): Card->getcardlist('1', '', 'rahul')
#3 {main}
  thrown in /var/www/ryapi/Db.php on line 179

why this error is coming please suggest.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡淡離愁欲言轉身 2024-10-15 18:09:31
CONCAT_WS(' ',firstname,lastname)  end)  like '%?%'

这里,'%?%' 不是 pdo 参数。
你应该这样做:

CONCAT_WS(' ',firstname,lastname)  end)  like ?

然后绑定:

Array
(
    [0] => 1
    [1] => '%rahul%'
)
CONCAT_WS(' ',firstname,lastname)  end)  like '%?%'

Here, '%?%' is not a pdo param.
You should make it:

CONCAT_WS(' ',firstname,lastname)  end)  like ?

Then bind:

Array
(
    [0] => 1
    [1] => '%rahul%'
)
彡翼 2024-10-15 18:09:31

这很可能是您的问题:

CONCAT_WS(' ',firstname,lastname)  end)  like '%?%'

绑定参数不能以这种方式工作,您需要将其更改为

CONCAT_WS(' ',firstname,lastname)  end)  like ?

并扩展使用通配符传入的值。

This is most likely your problem:

CONCAT_WS(' ',firstname,lastname)  end)  like '%?%'

Binding parameters does not work that way, you need to change it to

CONCAT_WS(' ',firstname,lastname)  end)  like ?

and extend the value you're passing in with the wildcards.

平生欢 2024-10-15 18:09:31

这是一个简单的错误,可以在 PHP 中修复。您还没有包含 PHP,所以我们无法判断。

您需要调整 的数量? pdo->prepare 语句中的符号。

This is a simple error that can be fixed in your PHP. You have not included the PHP, so we can't tell.

You need to adjust the number of ? symbols in your pdo->prepare statement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文