Home  >  Article  >  Backend Development  >  zend framework configuration operation database instance analysis_PHP tutorial

zend framework configuration operation database instance analysis_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:14:38870browse

After setting up the zendframework project environment, I took a look at the zend framework configuration and operation database. The PHP tutorial is as follows:
Create a config.ini file under the application/configs file
The configuration information is as follows :
[general]
db.adapter=PDO_MYSQL
db.config.host=localhost/IParess
db.config.username=username
db.config.password=password
db.config.dbname=databasename
2,
In the index.php page of the pulibc directory
/**Zend_Application*/
require_once 'Zend/Application.php';
Insert below
//set the datase config
require_once 'Zend/Config/Ini.php';
require_once 'Zend/Registry.php';
require_once 'Zend/Db.php';
require_once 'Zend/Db/Table.php';
$config=new Zend_Config_Ini('./../application/configs/config.ini',null, true);
Zend_Registry::set ('config',$config);
$dbAdapter=Zend_Db::factory($config->general->db->adapter,$config->general->db->config- >toArray());
$dbAdapter->query('SET NAMES UTF8');
Zend_Db_Table::setDefaultAdapter($dbAdapter);
Zend_Registry::set('dbAdapter',$dbAdapter ; Code

The code is as follows:

class Wp_posts extends Zend_Db_Table{ protected $_name = 'Wp_posts'; protected $_primary = ' ID';
}
?>


Create IndexController.php under the controller controller



Copy code

The code is as follows:
require_once APPLICATION_PATH.'/models/Wp_posts.php'; class IndexController extends Zend_Controller_Action {
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$con = new Wp_posts();
$res = $con ->fetchAll()->toArray();
$this->view->res = $res;
$this->render("index");
}
}


Create a view in views/scripts/index/: index.phtml



Copy the code

The code is as follows:
this is for test

res as $news){?>










ok, the browser displays:





http://www.bkjia.com/PHPjc/326241.htmlzend framework配置操作数据库www.bkjia.com

true

TechArticleAfter setting up the zendframework project environment, I looked at the zend framework configuration and operation database. The PHP tutorial is as follows: In application/configs Create a config.ini file under the file and the configuration information is as follows...
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