The examples in this article describe the Zend_db_table_rowset usage of Zend Framework frameworks. Share to everyone for your reference, specific as follows:
1. Introduction
Zend_db_table_rowset is an iterator of a collection of Zend_db_table_row objects. Typically, you cannot instantiate the zend_db_table_rowset yourself, but by calling Zend_db_table::find () method or the Fetchall () method to return Zend_db_table_rowset as the result data. You can then iterate through the Zend_db_table_row object set merge for modification.
2. Retrieve the result set
First, you need to instantiate a zend_db_table class.
<?php
//Set up a adapter
require_once ' zend/db.php ';
$params = Array (
' host ' => ' 127.0.0.1 ', '
username ' => ' malory ',
' password ' => '),
' dbname ' => ' Camelot '
);
$db = zend_db::factory (' Pdo_mysql ', $params);
Set the default
require_once ' zend/db/table.php ' for all zend_db_table objects;
Zend_db_table::setdefaultadapter ($db);
Connection 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 result returned 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 the table
$rowset = $table->fetchall ();
//$rowset is now a Zend_db_table_rowset object in which each record is a Zend_db_table_row object
//
?>
3. Traverse result set
Zend_db_table_rowset implements the iterator interface for a simple programming language, that is, the Zend_db_table_rowset object can be recycled, like using a foreach () function to work with arrays. Each value retrieved using this method is a Zend_db_table_row object of the data in the corresponding table, and you can view, modify, and save the object's properties (that is, the field values in the table).
<?php
//Connect to table class in database
Roundtable extends zend_db_table {}
$table = new Roundtable ();
Retrieving multiple records from the table
$rowset = $table->fetchall ();
Show All Records
foreach ($rowset as $row) {
//$row is a Zend_db_table_row object
echo "<p>". Htmlspecialchars ($r Ow->nobletitle). " "
. Htmlspecialchars ($row->firstname). "' s"
. " Favorite color is ". Htmlspecialchars ($row->favoritecolor)
. ". </p>/n";
Update the number of times we display the row
//(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 site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on the Zend Framework.