I have a problem with a query that works in phpmyadmin but not with Zend_db. You can read about the query in http://stackoverflow.com/questions/1268376/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.