Zendframework configuration operation database instance analysis

Source: Internet
Author: User
Tags php foreach wordpress database
After the zendframework project is created, I have read the zendframework configuration operation Database. This article will introduce it in detail. if you want to know more, refer to the zendframework project environment and check the zend framework configuration 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,
On the index. php page of the pulibc Directory
/** Zend_Application */
Require_once 'zend/Application. php ';
Insert
// 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: setdefaadapter adapter ($ dbAdapter );
Zend_Registry: set ('dbadapter ', $ dbAdapter );
In this case, I will use my local wordpress database for testing and use the wp_posts table for testing:
First, model models creates Wp_posts.php

The code is as follows:


Class Wp_posts extends Zend_Db_Table {
Protected $ _ name = 'WP _ posts ';
Protected $ _ primary = 'id ';
}
?>


Create IndexController. php under controller

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

The code is as follows:




This is for test










Res as $ news) {?>




OK. the browser displays:

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.