学习练习 Zend Framework ?xml version="1.0" encoding="UTF-8"?ConfigMysqlhost127.0.0.1/hostuserroot/userpassword111/passworddbnametest/dbname/Mysql/Config ?phprequire_once("Zend/Loader.php");//载入缓存类与Config类的子类XMLZend_Loader::loadCla
学习练习 Zend Framework
<?xml version="1.0" encoding="UTF-8"?> <Config> <Mysql> <host>127.0.0.1</host> <user>root</user> <password>111</password> <dbname>test</dbname> </Mysql> </Config>
<?php require_once("Zend/Loader.php"); //载入缓存类与Config类的子类XML Zend_Loader::loadClass("Zend_Cache"); Zend_Loader::loadClass("Zend_Config_Xml"); //实例化XML类(XML文件名,调用的节名) $XML = new Zend_Config_Xml('config.xml','Mysql'); //前端配置:指定主文件名(PHP文件名),开启序列化(必须) $Foptions = array('master_file' => 'Zend_Cache_File.php','automatic_serialization' => true); //开启缓存(前端,后端,前端配置) $Cache = Zend_Cache::factory('File','File',$Foptions); //讲实例化的XML对象资源保存到缓存,并命名 $Cache -> save($XML,'config'); //载入缓存 $Result = $Cache -> load('config'); //----------调用XML-------------- echo "主机名是:" . $Result ->host . "<br>"; echo "用户名是:" . $Result ->user . "<br>"; echo "密码是:" . $Result ->password . "<br>"; echo "库名是:" . $Result ->dbname . "<br>"; ?>