Zend_Db 查询 Mysqli 准备错误:操作数应包含 1 列

发布于 2024-08-02 00:18:15 字数 1227 浏览 6 评论 0原文

我的查询有问题,该查询在 phpmyadmin 中有效,但在 Zend_db 中无效。 您可以在具有多个连接的SQL语句中阅读有关查询的信息

我有这些表

Post
    ID
    entry
Category
    ID
    name
CategoryBinding
    ID
    postID
    categoryID

还有这个是我的 php 代码:

    class Blog_Model_DbTable_Posts extends Zend_Db_Table
    {
        protected $_name = 'Posts';
    public function getByCategoryId($id)
    {
            $query = 
    "SELECT * 
FROM `Post` AS `p` 
LEFT JOIN `CategoryBinding` AS `cb` ON p.ID = cb.postID 
LEFT JOIN `Category` AS `c` ON cb.categoryID = c.ID
INNER JOIN `Post` AS `p2` ON p.id = p2.id
WHERE p.id in
(
    SELECT p2.id
        FROM `Post` as `p2`
        LEFT JOIN `CategoryBinding` AS `cb` ON p2.ID = cb.postID 
        LEFT JOIN `Category` AS `c` ON cb.categoryID = c.ID
        WHERE c.id = 1
    )
    "
return parent::fetchAll($query);

我尝试使用 PDO 采用者 Boath 和 mysqli 采用者运行此查询。 我在 mysqli 采用者中遇到此错误。

Mysqli prepare error: Operand should contain 1 column(s)

我用谷歌搜索了一下,发现这可能是 Zend_Db 中的一个错误,但由于我的 sql 知识有些有限,我不知道我是否做错了什么,或者它是否确实是一个错误。 你能帮我解决这个问题吗? 保护你。

I have a problem with a query that works in phpmyadmin but not with Zend_db. You can read about the query in SQL statement with several joins

I have these tables

Post
    ID
    entry
Category
    ID
    name
CategoryBinding
    ID
    postID
    categoryID

And this is my php code:

    class Blog_Model_DbTable_Posts extends Zend_Db_Table
    {
        protected $_name = 'Posts';
    public function getByCategoryId($id)
    {
            $query = 
    "SELECT * 
FROM `Post` AS `p` 
LEFT JOIN `CategoryBinding` AS `cb` ON p.ID = cb.postID 
LEFT JOIN `Category` AS `c` ON cb.categoryID = c.ID
INNER JOIN `Post` AS `p2` ON p.id = p2.id
WHERE p.id in
(
    SELECT p2.id
        FROM `Post` as `p2`
        LEFT JOIN `CategoryBinding` AS `cb` ON p2.ID = cb.postID 
        LEFT JOIN `Category` AS `c` ON cb.categoryID = c.ID
        WHERE c.id = 1
    )
    "
return parent::fetchAll($query);

I have tried to run this query with boath the PDO adopter and with mysqli adopter. I get this error with the mysqli adopter.

Mysqli prepare error: Operand should contain 1 column(s)

I have googled about it and found that it maybe is a bug in Zend_Db, but since my sql knowledge is somewhat limited I do not know if I am doing something wrong or if it indeed is a bug. Can you please help me figuring this out?
Tank You.

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

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

发布评论

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

评论(1

饭团 2024-08-09 00:18:15

代替

parent::fetchAll($query);

使用

$this->getAdapter()->fetchAll($query);

Instead of

parent::fetchAll($query);

Use

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