The most basic usage of some traversal result sets and table operations in the ZF framework Db Class
1. [Code]FetchAll () method (commonly used)
// The fetchAll () method is also the most common traversal method // similar to mysql_fetch_array (). if the traversal requires a double-layer foreach loop $ Result = $ Db-> fetchAll ($ Select );
2. [Code]How to use fetchObject ()
// FetchObject () usage // returns the Result set while ($ Result = $ State-> fetchObject () {echo "ID :". $ Result-> s_id."
"; Echo" name: ". $ Result-> s_name ."
"; Echo "";}3. [Code]How to use fetchOnce ()
// FetchOnce () usage // read only one row of the Result set, which is generally used as a single query $ Result = $ Db-> fetchOne ($ SQL); echo $ Result;
4. [Code]How to use fetchAssoc ()
// FetchAssoc () usage // returns the Union array, similar to mysql_fetch_assoc () echo"
"; Foreach ($ Result as $ key => $ value) {echo"
"; Foreach ($ value as $ key2 => $ value2) {echo"
| ". $ Value2 ." | ";} Echo"
";} Echo"
";
5. [Code]Modification method
// The modification method that can be used directly after Zend_Db is instantiated $ Where ='s _ id = 1043 '; $ Set = array ('s _ dengji' => 999 ); $ Db-> update ($ table, $ Set, $ Where );6. [Code]Delete method
// The deletion method that can be used directly after Zend_Db is instantiated $ Mes = "s_id = 1041"; $ Db-> delete ($ table, $ Mes );
7. [Code]Add method
// The Add method that can be used directly after Zend_Db is instantiated $ table = 'hangzhou'; $ Mes = array ('s _ id' => '2016 ','s _ name' => 'Zhang San','s _ sheng '=> 'Shandong','s _ xian '=> 'jinan ','s _ gongzi' => 6000,'s _ dengji '=> 1); $ Db-> insert ($ table, $ Mes );8. [Code]Query method
// Query method that can be directly used after Zend_Db is instantiated $ SQL = "select * from sanguo"; $ Result = $ Db-> query ($ SQL ); $ Arr = $ Result-> fetchAll (); echo"
"; Foreach ($ Arr as $ row) {echo"
"; Foreach ($ row as $ k => $ v) {echo"
| ". $ V ." | ";} Echo"
";} Echo"
";?>