色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

zend framework配置操作數(shù)據(jù)庫(kù)實(shí)例分析

zendframework項(xiàng)目環(huán)境搭建后,看了下zend framework配置操作數(shù)據(jù)庫(kù),php教程如下:
在application/configs的文件下建立一個(gè)config.ini文件
配置信息如下
[general]
db.adapter=PDO_MYSQL
db.config.host=localhost/IParess
db.config.username=username
db.config.password=password
db.config.dbname=databasename
2、
在pulibc 目錄的index.php頁(yè)面中
/** Zend_Application */
require_once 'Zend/Application.php';
的下面插入
//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);
就此,我就用我的本地wordpress數(shù)據(jù)庫(kù)來(lái)測(cè)試下,就用wp_posts表來(lái)測(cè)試吧:
首先模型models建立Wp_posts.php
復(fù)制代碼 代碼如下:
<?php
class Wp_posts extends Zend_Db_Table{
protected $_name = 'Wp_posts';
protected $_primary = 'ID';
}
?>

控制器controller下面建立IndexController.php
復(fù)制代碼 代碼如下:
<?php
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");
}
}

在views/scripts/index/ 建立視圖:index.phtml
復(fù)制代碼 代碼如下:
<html>
<head>
<title>this is for test</title>
</head>
<body>
<table>
<?php foreach ($this->res as $news){?>
<tr>
<td><?php echo $news['id']?></td>
<td><?php echo $news['post_title']?></td>
<td><?php echo $news['post_date']?> </td>
</tr>
<?php }?>
</table>
</body>
</html>

ok啦,瀏覽器顯示:
zend framework配置操作數(shù)據(jù)庫(kù)

php技術(shù)zend framework配置操作數(shù)據(jù)庫(kù)實(shí)例分析,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 济宁市| 汉源县| 海伦市| 雷州市| 滦平县| 嘉禾县| 古浪县| 江阴市| 裕民县| 绵竹市| 临潭县| 临高县| 新丰县| 德州市| 大洼县| 湖北省| 绵阳市| 高清| 天柱县| 珠海市| 准格尔旗| 宜州市| 阿城市| 高唐县| 庆阳市| 临城县| 义乌市| 抚州市| 蒙阴县| 当阳市| 滨州市| 沈阳市| 磐石市| 灵丘县| 岚皋县| 保靖县| 绥德县| 中牟县| 香格里拉县| 田林县| 正安县|