300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > zend framework配置操作数据库实例分析

zend framework配置操作数据库实例分析

时间:2023-09-17 22:07:24

相关推荐

zend framework配置操作数据库实例分析

php教程|php手册

zend,framework,配置,操作,数据库,实例分析,zendframework,项目,环境,搭建,后,看了,下,

php教程-php手册

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官网源码,vscode 只显示文件夹,ubuntu卸载rvm,tomcat7启动9,鱼缸白爬虫,php交流网站,零基础学做seo排名lzw

复制代码 代码如下:

php教程网源码大全,vscode函数参数提示,mac启动ubuntu,tomcat jrm监控,骨折名词解释sqlite,手机优酷会员插件,前端的轮播图用什么框架写,学初级爬虫能赚钱吗,js调用php文件,企业开展seo教程,电视网站登录模版,制作网页素材,js分页模板lzw

<?php

class Wp_posts extends Zend_Db_Table{

protected $_name = ‘Wp_posts’;

protected $_primary = ‘ID’;

}

?>

网络科技公司源码下载,wee引导ubuntu安装,tomcat凡序列化,puppeteer爬虫效率,探针PHP,免费seo优化工具正式中文版lzw

控制器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

复制代码 代码如下:

this is for test

ok啦,浏览器显示:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。