ankit
ankit

Reputation: 295

straight join in zend framework

I have used left join in using zend framework/mysql using Zend_Db_Table::getDefaultAdapter. Does this also support straight join ? If yes, how do i do that? I tried checking in documentation. Couldn't find. Thanks for the help

Upvotes: 0

Views: 754

Answers (2)

user2448995
user2448995

Reputation: 31

I use this hack of Zend_Db_Select:

$select->from($tableName, array(new Zend_Db_Expr(' STRAIGHT_JOIN ' . $tableName . '.*'));

Hope this helps somebody.

Upvotes: 3

Thomas Fussell
Thomas Fussell

Reputation: 468

Looking at the Zend source, it seems that there is no support for a STRAIGHT_JOIN when using Zend_Db_Select. You may however write the SQL statement yourself and then execute it directly using the DB adapter:

$db = Zend_Db_Table::getDefaultAdapter();

//Taken from: http://framework.zend.com/manual/en/zend.db.adapter.html#zend.db.adapter.select.fetchall
$sql = 'SELECT * FROM bugs WHERE bug_id = ?';
$result = $db->fetchAll($sql, 2);

If you already have a complicated query using Zend_Db_Select, you can use the __toString() method and use that string as a basis for your modified query.

//Taken from: http://framework.zend.com/manual/en/zend.db.select.html#zend.db.select.execute.tostring
$select = $db->select()->from('products');
$sql = $select->__toString();

Upvotes: 0

Related Questions