3. Zend_Db_Select
using query to fetch rowset.
// Create the Zend_Db_Select object
$select = $db->select(); //if inside the table class $db is $this->_db; $this->_db is setted in the Initializer.php file: Zend_Db_Table_Abstract::setDefaultAdapter($db);
// Add a FROM clause
$select->from( $table[, $columns] ); //specify table and columns
// Add a WHERE clause
$select->where([$query_condition]); //specify search criteria
// Add an ORDER BY clause
$select->order( [$order] ); //specify sorting criteria
3.1 from() function:
Code
3.2 Adding Another Table to the Query with JOIN
function join($table, $join, [$columns]); $table is the table name you want to join, $join is the join codition, $columns is an array of field columns in the joined table, default is *, if array() that means no column is needed.
joinInner() is the same as join();
others join function:
joinLeft($table, $join, [$columns]), joinRight($table, $join, [$columns]), joinFull($table, $join, [$columns]);
joinCross($table, [$columns]); joinNatural($table, [$columns]) ; no join condition
3.3 Adding a WHERE, GOURP BY, ORDER BY, LIMIT Clause
Code
3.4 Adding the DISTINCT Query Modifier
Code
3.5 Executing Select Queries
Two ways:
Code
using query to fetch rowset.
// Create the Zend_Db_Select object
$select = $db->select(); //if inside the table class $db is $this->_db; $this->_db is setted in the Initializer.php file: Zend_Db_Table_Abstract::setDefaultAdapter($db);
// Add a FROM clause
$select->from( $table[, $columns] ); //specify table and columns
// Add a WHERE clause
$select->where([$query_condition]); //specify search criteria
// Add an ORDER BY clause
$select->order( [$order] ); //specify sorting criteria
3.1 from() function:
3.2 Adding Another Table to the Query with JOIN
function join($table, $join, [$columns]); $table is the table name you want to join, $join is the join codition, $columns is an array of field columns in the joined table, default is *, if array() that means no column is needed.
joinInner() is the same as join();
others join function:
joinLeft($table, $join, [$columns]), joinRight($table, $join, [$columns]), joinFull($table, $join, [$columns]);
joinCross($table, [$columns]); joinNatural($table, [$columns]) ; no join condition
3.3 Adding a WHERE, GOURP BY, ORDER BY, LIMIT Clause
3.4 Adding the DISTINCT Query Modifier
3.5 Executing Select Queries
Two ways: