I got app that need to be recoded in CakePHP.
I got following select with subselects:
SELECT COUNT(*) AS item1,
(SELECT COUNT(*) FROM portal_members) AS item3,
(SELECT COUNT(*) FROM portal_reviews) AS item3,
(SELECT COUNT(*) FROM portal_downloads) AS item4
FROM portal_articles
WHERE 1 = 1
Anyone have any idea how to create that query using CakePHP find($type, $params) ?
If that is your exact query, I'd recommend doing it in four passes.
$item1 = $this->PortalArticle->find('count');
$item2 = $this->PortalReview->find('count'); // etc..
It might take a wee bit longer to run, but your intentions are much clearer and the code would be much cleaner.
Please try this code
$this->loadModel('PortalArticle');
$db = $this->PortalArticle->getDataSource();
$a = $db->fetchAll(
' SELECT COUNT(*) AS item1,
(SELECT COUNT(*) FROM portal_members) AS item3,
(SELECT COUNT(*) FROM portal_reviews) AS item3,
(SELECT COUNT(*) FROM portal_downloads) AS item4
FROM portal_articles
WHERE 1 = 1'
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With