Introduction
Some simple examples of how to handle Zend Framework DB Table Queries.
Select
- Using the shortcut Find operation to find a Row by a primary key
// Query to check whether the Answer is correct for the question ID $class = $this->social->config->path->models . 'Trivia'; $table = new $class(); $result = $table->find($this->_getParam('qid')); $triviaRow = $result->current();
- Fetching all the returned rows
// Query to get the user Favourite team $class = $this->social->config->path->models . 'UserTeamView'; $table = new $class(); $where = array('user_id = ?' => $this-> social-> uId); $order = 'order'; $row = $table->fetchRow($where, $order);
Insert
- Using the shortcut Find operation to find a Row by a primary key
// Query to insert Users who are interacting with the application type = User $class = $this->social->config->path->models . 'User'; $table = new $class(); 'id' => $this->social->uId, 'network' => $this->social->name, 'type' => $this->social->type, 'proxied_email' => null, 'status' => 'User' ); $result = $table->insert($data);
Update
- Using the shortcut Find operation to find a Row by a primary key
// Query to update the users total points $table = new Default_Model_DBTable_UserDetail; $data = array('points_trivia' => new Zend_Db_Expr ('`points_trivia` + ' . $pointsGained)); $where = $table->getAdapter()->quoteInto('id = ?', $this->_getParam('fb_sig_user')); $updateUser = $table->update($data, $where); // Instatiate the Model $table = new Default_Model_DBTable_Account(); // Query to update the Account table 'reference_id' => $dataArray['data']['reference'], 'invoice' => $dataArray['data']['invoice'], 'vat' => $dataArray['data']['vat'] ); $where = $table->getAdapter()->quoteInto('id = ?', $this->_getParam('id')); $result = $table->update($data, $where);
External Links
|