View Single Post
  #1 (permalink)  
Old 06-28-2008, 04:58 AM
fossil_007 fossil_007 is offline
Junior Member
 
Join Date: Apr 2008
Posts: 10
Default Zend DB usage confusinon,use model or sql query?

Hi all I am confused,
Which is the better way to use zend db, is it by writing pure own sql queries
And use in select statements)as in PART A below) or use models of tables and join with
Given model relationships (PART B below)
------------------------------------------------------------------
Example PART A
------------------------------------------------------------------
$select*=*$db->select()
****->from(array('p'*=>*'products'),
********array('product_id'))
****->join(array('l'*=>*'line_items'),
********'p.product_id*=*l.product_id',
********array('line_items_per_product'*=>*'COUNT(* )'))
****->group('p.product_id')
****->having('line_items_per_product*>*10');

------------------------------------------------------------------
<?php
$db*=*Zend_Db::factory(*...options...*);
$select*=*$db->select();

------------------------------------------------------------------
$sql*=*'SELECT***FROM*bugs*WHERE*bug_id*=*?';

$result*=*$db->fetchAll($sql,*2);
------------------------------------------------------------------

//////////////// OR /////////////////////

------------------------------------------------------------------
Example PART B
------------------------------------------------------------------
class*Products*extends*Zend_Db_Table_Abstract
{
****protected*$_name************=*'products';
****protected*$_dependentTables*=*array('BugsProdu cts');
}

class*Bugs*extends*Zend_Db_Table_Abstract
{
****protected*$_name************=*'bugs';

****protected*$_dependentTables*=*array('BugsProdu cts');

****protected*$_referenceMap****=*array(
********'Reporter'*=>*array(
************'columns'***********=>*'reported_by',
************'refTableClass'*****=>*'Accounts',
************'refColumns'********=>*'account_name'
********),

--------------------------------------------------------------------------------
<?php
$bugs*=*new*Bugs();
$row*=*$bugs->fetchRow('bug_id*=*1');
------------------------------------------------------------------

I understand each will have their benefits but which one is preferable
Like in joining the table with defining relationships we the data retrieved will be read
Only. Please help me,
Thank you for your help and time
Reply With Quote