I have a normal mysql select and I would like to rewrite it to a Zend Framework mysql select. Here is my select:
$sql = "
SELECT
IF(mu.recieverUserId = '{$userId}', u.senderUserId,
mu.recieverUserId) friend1,
u.mesaj, u.senderUserId, mu.recieverUserId,
u.created
FROM
(SELECT *
FROM mesaje
ORDER BY `created` desc) AS u
LEFT JOIN `mesaje_utilizatori` AS `mu` ON u.id=mu.mesajId
WHERE (mu.recieverUserId = '{$userId}' OR u.senderUserId='{$userId}')
GROUP BY friend1 ASC
ORDER BY `u`.`created` DESC, u.id DESC
";
Here is the documentation: Zend_Db_Statement
Zend Query
$sql = $db->query(
'SELECT
IF(mu.recieverUserId = ?, u.senderUserId,
mu.recieverUserId) friend1,
u.mesaj, u.senderUserId, mu.recieverUserId,
u.created
FROM
(SELECT *
FROM mesaje
ORDER BY `created` desc) AS u
LEFT JOIN `mesaje_utilizatori` AS `mu` ON u.id=mu.mesajId
WHERE (mu.recieverUserId = ? OR u.senderUserId = ? )
GROUP BY friend1 ASC
ORDER BY `u`.`created` DESC, u.id DESC',
array($userId, $userId,$userId)
);
Zend Result
while ($row = $sql->fetch()) {
Zend_Debug::dump($row);
}
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