Zend Framework連接Mysql數(shù)據(jù)庫實(shí)例分析
本文實(shí)例講述了Zend Framework連接Mysql數(shù)據(jù)庫的方法。分享給大家供大家參考,具體如下:
在看這些之前請確保你正確加載了PDO擴(kuò)展。做法是編輯php.ini 。
手動(dòng)增加這兩行(前面要沒有分號(hào);):
extension=php_pdo.dll extension=php_pdo_mysql.dll
然后要把extension_dir
指向php_pdo.dll及php_pdo_mysql.dll所在目錄,如
extension_dir = "C:/php5/ext"
OK,let's go..
index.php 網(wǎng)站首頁,也是唯一入口
<?php
//...省略
$params = array ('host' => '127.0.0.1',
'username' => 'root',
'password' => '123456',
'dbname' => 'happycms');
$db = Zend_Db::factory('pdoMysql', $params);
Zend::register('db', $db);
?>
lib/App/Article.php
<?php
class App_Article {
private $db;
function App_Article() {
$this->db = Zend::registry('db');
}
function listAll() {
$result = $this->db->query('SELECT * FROM article');
$rows = $result->fetchAll();
Zend::dump($rows);
}
function listByCategory() {
}
//...省略
}
?>
ArticleController.php
class articleController extends Zend_Controller_Action {
private $view;
private $article;
function __c****truct() {
$this->view = Zend::registry('view');
$this->article = new App_Article();
}
public function listAllAction() {
$this->article->listAll();
$this->view->title='View Articles';
echo $this->view->render(TPL_DIR.'/tplView.php');
}
function __call($action, $arguments)
{
$this->_redirect('./');
print_r($action);
print_r($arguments);
}
}
?>
訪問 http://happycms/article/listall
得到以下輸出:
array(1) {
[0] => array(15) {
["articleid"] => string(1) "1"
["categoryid"] => string(1) "0"
["articletitle"] => string(4) "test"
["articlefromwhere"] => string(3) "sdf"
["articlekeywords"] => string(5) "sdfds"
["articledescription"] => string(4) "test"
["articlebody"] => string(9) "sffsdfsdf"
["authorname"] => string(8) "haohappy"
["authoremail"] => string(11) "s...@df.com"
["issticky"] => string(1) "0"
["isrecommanded"] => string(1) "0"
["includeattachment"] => string(1) "0"
["addtime"] => string(19) "0000-00-00 00:00:00"
["lastedittime"] => string(19) "0000-00-00 00:00:00"
["checktime"] => string(19) "0000-00-00 00:00:00"
}
更多關(guān)于zend相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Zend FrameWork框架入門教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《Yii框架入門及常用技巧總結(jié)》、《ThinkPHP入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家基于Zend Framework框架的PHP程序設(shè)計(jì)有所幫助。
- Zend Framework 2.0事件管理器(The EventManager)入門教程
- Zend Framework數(shù)據(jù)庫操作技巧總結(jié)
- Zend Framework數(shù)據(jù)庫操作方法實(shí)例總結(jié)
- Zend Framework入門教程之Zend_Db數(shù)據(jù)庫操作詳解
- ZendFramework框架實(shí)現(xiàn)連接兩個(gè)或多個(gè)數(shù)據(jù)庫的方法
- Zend Framework教程之連接數(shù)據(jù)庫并執(zhí)行增刪查的方法(附demo源碼下載)
- 解析如何使用Zend Framework 連接數(shù)據(jù)庫
- zend framework配置操作數(shù)據(jù)庫實(shí)例分析
- windows下zendframework項(xiàng)目環(huán)境搭建(通過命令行配置)
- zend framework多模塊多布局配置
- Zend Framework開發(fā)入門經(jīng)典教程
- ZendFramework2連接數(shù)據(jù)庫操作實(shí)例
相關(guān)文章
PHP調(diào)用FFmpeg實(shí)現(xiàn)視頻切片
這篇文章主要為大家詳細(xì)介紹了PHP如何調(diào)用FFmpeg實(shí)現(xiàn)視頻切片功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2025-02-02
TP5框架實(shí)現(xiàn)的數(shù)據(jù)庫備份功能示例
這篇文章主要介紹了TP5框架實(shí)現(xiàn)的數(shù)據(jù)庫備份功能,結(jié)合實(shí)例形式分析了TP5數(shù)據(jù)庫備份功能相關(guān)原理及實(shí)現(xiàn)方法,需要的朋友可以參考下2020-04-04
PHP數(shù)組和explode函數(shù)示例總結(jié)
有關(guān)php分割字符串explode函數(shù)的用法,使用explode函數(shù)將字符串分割到數(shù)組,這里給大家總結(jié)了幾個(gè)示例,需要的朋友參考下。2015-05-05
YII Framework學(xué)習(xí)之request與response用法(基于CHttpRequest響應(yīng))
這篇文章主要介紹了YII Framework學(xué)習(xí)之request與response用法,詳細(xì)介紹了CHttpRequest響應(yīng)request與response的使用技巧,需要的朋友可以參考下2016-03-03
PHP 提取圖片img標(biāo)記中的任意屬性的簡單實(shí)例
這篇文章主要介紹了PHP 提取圖片img標(biāo)記中的任意屬性的簡單實(shí)例,有需要的朋友可以參考一下2013-12-12

