Zf Zend Db by aida
Upcoming SlideShare
Loading in...5
×
 

Zf Zend Db by aida

on

  • 2,192 views

 

Statistics

Views

Total Views
2,192
Views on SlideShare
2,188
Embed Views
4

Actions

Likes
1
Downloads
3
Comments
0

2 Embeds 4

http://www.slideshare.net 3
http://ss.dotbranch.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Zf Zend Db by aida Zf Zend Db by aida Presentation Transcript

  • Zend_Db 2010 / 03 / 06
  • • Zend_Framework • Zend_Db •
  • Zend_Framework 2008 6 1 Zend_Framework Ver1.5 8 Zend_Framework AX_Framework1.0 6 AX_Framework
  • Zend_Db Zend_Db Zend_Db_Adapter DB Zend_Db_Table DB a) Zend_Db_Table DAO select insert update b) Zend_Db_Table Zend_Db_Table_Row Zend_Db_Tabl e_Rowset
  • Zend_Db Zend_Db_Adapter DB // $params = array( 'host' => 'localhost', 'username' => 'webuser', 'password' => 'xxxxxxxx', 'dbname' => 'test' ); $db = Zend_Db::factory('Pdo_Mysql', $params); // $results = $db->fetchAll('SELECT * FROM book WHERE id = ?', 123); // $data = array( 'created' => time(), 'tite' => ' 1 ', 'author' => ' ' ); $db->insert('book', $data);
  • Zend_Db Zend_Db_Table DB a) // DAO class BookDAO extends App_Db_Table { protected $_name = 'book'; public function getBooksByAuthor($author) {...} public function insert($data) {...} } // DAO $dao = new BookDAO(); // $rowset = $dao->fetchAll(); $rowset = $dao->getBooksByAuthor(' '); // $data = array('tite' => ' ','author' => ' '); $dao->insert($data);
  • Zend_Db Zend_Db_Table DB b) // Table class BookTable extends App_Db_Table { protected $_name = 'book'; protected $_rowClass = 'BookRow'; protected $_rowsetClass = 'BookRowset'; public function getBooksByAuthor($author) { } } // Row class BookRow extends App_Db_Table_Row { } // Rowset class BookRowset extends App_Db_Table_Rowset { } // Table $table = new BookTable(); // $rowset = $table->fetchAll(); $rowset = $table->getBooksByAuthor(' '); // $data = array('tite' => ' ', 'author' => ' '); $row = $table->createRow($data); $row->save();
  • Zend_Db Zend_Db_Table DB b)
  • Zend_Db Table getXXX getXXX Rowset Array select Row Rowset
  • Zend_Db
  • Zend_Db Table 1. select Zend_Db_Table_Select 2. createRow() 3. static
  • Zend_Db Table // Table class BookTable extends App_Db_Table { protected $_name = 'book'; protected $_rowClass = 'BookRow'; protected $_rowsetClass = 'BookRowset'; public function selectActive() { return parent::select('deleted IS NULL'); } public function selectByAuthor($author) { return $this->selectActive()->where('author = ?', $author); } } // Table $table = new BookTable(); // $rowset = $table->fetchAll($table->selectByAuthor(' ')); $rowset = $table->fetchAll($table->selectByAuthor(' ')->where('created < ', '1992-03-31')); Select →DRY Zend_Db
  • Zend_Db Row Row Rowset User < > Blog < > Comment // Row class BlogRow extends App_Db_Table_Row { public function getUser() { $userTable = new UserTable(); return $userTable->find($this->user_id)->current(); } public function getComments() { $commentTable = new CommentTable(); return $commentTable->fetchAll($commentTable->select()->where('blog_id = ?', $this->id)); } } // Table $table = new BlogTable(); // BlogRow $row = $table->find(123)->current(); // Blog $nickname = $row->getUser()->nickname; // Blog $comments = $row->getComments();
  • Zend_Db Rowset // Rowset class BookRowset extends App_Db_Table_Rowset { public function toArrayGroupByAuthor() { $array = array(); while ($this->valid()) { $row = $this->current(); $array[$row->author] = isset($array[$row->author]) ? array_push($array[$row->author], $row) : array($row); $this->next(); } } } // Table $table = new BookTable(); // Author $authorsArray = $table->fetchAll()->toArrayGroupByAuthor();