Zend Framework Framework Tutorial Zend_db_table_rowset Usage Example analysis, ZENDFRAMEWORK2 instance
The examples in this article describe the Zend_db_table_rowset usage of the Zend Framework framework. Share to everyone for your reference, as follows:
1. Introduction
Zend_db_table_rowset is an iterator to the collection of Zend_db_table_row objects. In general, you cannot instantiate zend_db_table_rowset yourself, but by calling Zend_db_table::find () method or the Fetchall () method returns the Zend_db_table_rowset as the result data. You can then iterate through the Zend_db_table_row object set Merge to make the changes.
2. Retrieving the result set
First, you need to instantiate a zend_db_table class.
<?php//set a adapterrequire_once ' zend/db.php '; $params = Array ( ' host ' = ' 127.0.0.1 ', ' username ' = > ' Malory ', ' password ' = ' ****** ', ' dbname ' = ' Camelot '); $db = Zend_db::factory (' Pdo_mysql ', $ params);//Set default require_once ' zend/db/table.php ' for all zend_db_table objects; Zend_db_table::setdefaultadapter ($DB);//Connect database table class RoundTable extends Zend_db_table {} $table = new RoundTable (); >
Next, you can use the Zend_db_table::find () method and multiple key values, or use the Zend_db_table::fetchall () method to query the database.
The returned result is a Zend_db_table_rowset object through which each Zend_db_table_row object in the result set can be traversed.
<?php//retrieve multiple records from a table $rowset = $table->fetchall ();////$rowset is now a Zend_db_table_rowset object, and each record in that object is a zend_db_ Table_row Object//?>
3. Traverse the result set
Zend_db_table_rowset implements the iterator interface for a simple programming language, which means that the Zend_db_table_rowset object can be looped, as if using foreach () Functions work with arrays. Each value retrieved using this method is a Zend_db_table_row object that corresponds to the data in the table, and you can view, modify, and save the properties of the object (that is, the field values in the table).
<?php//connecting to a table in a database class RoundTable extends Zend_db_table {} $table = new RoundTable ();//Retrieve multiple records from a table $rowset = $table->f Etchall ();//Show All records foreach ($rowset as $row) { //$row is a Zend_db_table_row object echo "" . Htmlspecialchars ($row->nobletitle). " " . Htmlspecialchars ($row->firstname). "' s" . Favorite color is ". Htmlspecialchars ($row->favoritecolor) . ".
/n "; Update we show the number of changes //(the "times_displayed" field in the corresponding table) $row->timesdisplayed + +; Save the new record. $row->save ();}? >
More interested in Zend related content readers can view the topic: "Zend framework of the introductory tutorial", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Tutorial", "PHP object-oriented Programming introduction tutorial "," Introduction to Php+mysql Database Operation "and" PHP common database Operation Skills Summary "
It is hoped that this article will help you to design PHP based on the Zend Framework framework.
Articles you may be interested in:
- Zend Framework Tutorial Zend_db_table_row Usage Example Analysis
- Zend Framework Tutorial Zend_db_table Usage
- Zend Framework Tutorial Zend_form component implement form submission and display Error prompt method
- Introduction to Zend Framework Development Classic Tutorial
- Zend Framework Smarty Extension Implementation method
- Code analysis of routing mechanism of Zend framework framework
- Zend Framework implementation of basic functions of the message book (with demo source download)
- The Zend framework implements the method of storing the session in Memcache
- Zend Framework Paging Class usage
- Zend Framework implements multi-file upload function instances
- Zend Framework Introduction Environment configuration and the first Hello World example (with demo source download)
- Zend Framework Tutorial to connect the database and perform additions and deletions of the method (attached to the demo source download)
- Zend Framework Tutorial Zend_db_table Table Association Instance detailed
http://www.bkjia.com/PHPjc/1113740.html www.bkjia.com true http://www.bkjia.com/PHPjc/1113740.html techarticle Zend Framework Framework Tutorial Zend_db_table_rowset Usage Example Analysis, ZENDFRAMEWORK2 example This article describes Zend Framework framework zend_db_table_rowset usage. Share for the big ...