The most basic usage of some traversal result sets and table operations in the ZF framework Db Class-PHP source code

Source: Internet
Author: User
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"
    ";} Echo"
   ";} Echo"
  
". $ Value2 ."
";
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"
    ";} Echo"
   ";} Echo"
  
". $ V ."
";?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.