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

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Zf Zend Db by aida

1,653

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,653
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide















  • Transcript

    • 1. Zend_Db 2010 / 03 / 06
    • 2. • Zend_Framework • Zend_Db •
    • 3. Zend_Framework 2008 6 1 Zend_Framework Ver1.5 8 Zend_Framework AX_Framework1.0 6 AX_Framework
    • 4. 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
    • 5. 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);
    • 6. 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);
    • 7. 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();
    • 8. Zend_Db Zend_Db_Table DB b)
    • 9. Zend_Db Table getXXX getXXX Rowset Array select Row Rowset
    • 10. Zend_Db
    • 11. Zend_Db Table 1. select Zend_Db_Table_Select 2. createRow() 3. static
    • 12. 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
    • 13. 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();
    • 14. 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();

    ×