激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

香港云服务器
服務(wù)器之家 - 編程語言 - PHP教程 - zend framework配置操作數(shù)據(jù)庫實(shí)例分析

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

2020-01-20 16:17PHP教程網(wǎng) PHP教程

zend framework項(xiàng)目建立后,看了下zend framework配置操作數(shù)據(jù)庫,本文將詳細(xì)介紹,需要了解的朋友可以參考下

zendframework項(xiàng)目環(huán)境搭建后,看了下zend framework配置操作數(shù)據(jù)庫,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頁面中 
/** 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ù)庫來測(cè)試下,就用wp_posts表來測(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ù)庫實(shí)例分析

 

延伸 · 閱讀

精彩推薦
461
主站蜘蛛池模板: 亚洲精品成人悠悠色影视 | 免费黄色在线 | 天天草天天爱 | 99久久精约久久久久久清纯 | 成人网视频 | 欧洲精品久久久久69精品 | 国产一级毛片高清视频 | 成人精品视频在线 | 干一夜综合 | 一道本不卡一区 | 一区二区三区欧美在线 | 色av综合在线 | a免费视频 | 成人在线观看免费 | 逼片视频| 久久成年网站 | 久草成人在线观看 | av免费在线免费观看 | 麻豆小视频在线观看 | 久久伊人国产精品 | 一区二区三区国产在线 | 国产午夜精品一区二区三区免费 | 久久不射电影网 | 在线观看第一区 | 永久av在线免费观看 | 欧美一区在线观看视频 | 免费黄色大片在线观看 | av电影免费观看 | 国产精品久久久久久影院8一贰佰 | 欧美日韩在线视频一区 | 久久久久久久一区二区 | 2021国产精品视频 | 草操影院 | av成人在线免费观看 | 色淫视频 | 色午夜日本| 亚洲国产视频在线 | 精品一区二区久久久久久久网精 | 久久国产精品久久精品国产演员表 | 亚洲91网| 斗罗破苍穹在线观看免费完整观看 |