Tuesday, May 15, 2012

Zend DB Select join

Example of joining table using dbtable (EntStudio_Db_Table_Abstract)

$maintable = "x";

$query = $dbtable->select();
$query->setIntegrityCheck(false);
$query->from($dbtable, array("*")); //only specify column for main table

   
$query->join(array("u" => "table2"),  $maintable . ".userid=u.id", array("username")); //only specify column for table2

to output to test:
echo $query;

to get results:

$resultSet = $dbtable->fetchAll($query);
$entries   = array();
foreach ($resultSet as $row) {
//... codes here
}


to get a single row:
$row = $dbtable->fetchRow($query);

No comments: