2008年7月30日星期三

Re: [fw-db] Using the Zend_Db_Table to return referenced row values

One of my favorite benefits of using select objects is that it's much easier to make conditional select queries. For example, I have a page that displays user-created public groups. But if the user is logged in, the select query is modified to also include subscribed private groups by joining the subscriptions table. I'm very thankful that Zend_Db_Select is flexible enough to make this easy.

Is it possible to import a select query string into Zend_Db_Select and convert it to a select object? That would be pretty neat!

<?php

$sql = "SELECT * FROM `table` WHERE 1";
$select = Zend_Db_Select::import($sql);

?>

Micah Gersten wrote:
One of the main reasons to use a SQL abstraction layer is so that DB engines can change if need be without too much trouble.    Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com    dele454 wrote:   
Indeed PDO is much more readable - with a good indentation implemented. I think there is definitely a place for Db Object Models one just has to find a balance between the two ie. when it is appropriate and convienient to go the object way or to simply stick to plain sql. I find plain sql much more simpler especially when you have written and testing your queries before hand. You simply copy and paste and not have to worry about the intricacies of how a Frameworks interpretes nested joins or queries :)  Am using a combination of both for now.    monk.e.boy wrote:        
 >>  Your query is this:  I ask thee, which is easier to read and understand? ::    $sql = <<<EOT       SELECT e.eventName, v.VenueName, c.City     FROM EventVenue ev     LEFT JOIN Event e ON ev.eventid=e.eventid     LEFT JOIN Venue v ON ev.venueid=v.venueid     LEFT JOIN Area a ON e.areaid=a.areaid     LEFT JOIN City c ON a.cityid=c.cityid;  EOT;   ---- or ----  $sql = $this->select()->setIntegrityCheck(false)     ->from($this, array() )     ->joinLeftUsing( array('e'=>'Event'), 'EventId', array('EventName') )     ->joinLeftUsing( array('v'=>'Venue'), 'VenueId', array('VenueName') )     ->joinLeft( array('a'=>'Area'), 'e.AreaId = a.AreaId', array() )     ->joinLeft( array('c'=>'City'), 'a.CityId = c.CityId', array('City') );  Object models are a neat idea, but good god, the code is a mess. It's starting to look like Perl....   monk.e.boy             
 ----- dee        
    

没有评论: