Home  >  Article  >  Backend Development  >  Simple usage of ZF framework Db class stater

Simple usage of ZF framework Db class stater

WBOY
WBOYOriginal
2016-07-25 08:48:41964browse
homework exercises
  1. /*How to use the stater*/
  2. //Introduce the Loader class (automatic loading class)
  3. require_once("Zend/Loader.php");
  4. //Use the Loader class to introduce a Db class
  5. Zend_Loader::loadClass("Zend_Db");
  6. //Introducing Zend_Db's stater
  7. Zend_Loader::loadClass("Zend_Db_Statement_Pdo");
  8. //Configuring database connection information
  9. $Config = array('host' => ; '127.0.0.1' ,
  10. 'username' => 'root' ,
  11. 'password' => '111' ,
  12. 'dbname' => 'test'
  13. );
  14. //Tell the Zend_Db class what to do Database and database configuration information
  15. $Db = Zend_Db::factory('PDO_Mysql' , $Config);
  16. //Execute encoding statement
  17. $Db -> query("set names utf8");
  18. //Temporarily this is A table name variable
  19. $table = 'sanguo';
  20. //SQL statement, conditions are replaced by ? numbers
  21. $Sql = "select * from sanguo";
  22. //Instantiate the state device of Zend_Db
  23. $State = new Zend_Db_Statement_Pdo($Db, $Sql);
  24. //Execute the SQL statement
  25. $State -> execute();
  26. //Return the executed SQL result set (requires loop)
  27. $Result = $State -> fetchAll( );
  28. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn