国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

zend framework配置操作數據庫實例分析

2024-05-04 23:13:20
字體:
來源:轉載
供稿:網友

zendframework項目環境搭建后,看了下zend framework配置操作數據庫,php教程如下:
在application/configs的文件下建立一個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頁面中
/** 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數據庫來測試下,就用wp_posts表來測試吧:
首先模型models建立Wp_posts.php

復制代碼 代碼如下:


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


控制器controller下面建立IndexController.php

復制代碼 代碼如下:


<?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

復制代碼 代碼如下:


<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配置操作數據庫實例分析

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 河东区| 台湾省| 格尔木市| 玉林市| 清苑县| 万安县| 四川省| 罗江县| 唐海县| 香港 | 隆林| 榆树市| 长武县| 改则县| 江都市| 濉溪县| 股票| 周至县| 贵溪市| 涟源市| 吕梁市| 苍溪县| 林芝县| 轮台县| 方正县| 自贡市| 西盟| 仁怀市| 甘洛县| 嘉黎县| 邳州市| 灵璧县| 赣榆县| 石河子市| 澄江县| 双江| 同心县| 澄江县| 涟水县| 喀喇沁旗| 汤阴县|