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.