Zend_Db without Zend Framework(Zend_Db 没有 Zend 框架)
问题描述
我想在没有 Zend_Framework 的情况下使用 Zend_Db.我想为我现有的不是使用 Zend Framework 制作的网站合并 Zend_Db.是否可以像这样使用 Zend_Db?你能推荐好的教程或例子吗?
I want using Zend_Db without Zend_Framework. I want incorporate Zend_Db for my existing website that was not made using Zend Framework. Is it possible to use Zend_Db like this? Can you recommend good tutorial or example how to do it good?
推荐答案
在某种程度上,这取决于您使用的 Web 框架.但是,总的来说,Zend_Db 文档在这方面.
To some extent, this depends upon the web framework you are using. But, in general, the Zend_Db documentation is pretty clear in this regard.
在您的引导程序中创建一个适配器实例.举个例子:
Create an adapter instance in your bootstrap. As an example:
$db = Zend_Db::factory('Pdo_Mysql', array(
'host' => '127.0.0.1',
'username' => 'webuser',
'password' => 'xxxxxxxx',
'dbname' => 'test'
));
如果您打算使用 Zend_Db_Table,那么您可以将其设为默认适配器:
If you plan to use Zend_Db_Table, then you can make this the default adapter:
Zend_Db_Table::setDefaultAdapter($db);
无论如何,将此适配器保存在您可以访问的地方会很有帮助.例如:
In any case, it's helpful to have this adapter saved someplace where you can access it. For example:
Zend_Registry::set('db', $db);
然后在您的下游代码中,使用此适配器为 select()、insert()、update()、delete() 等:
Then in your downstream code, use this adapter to create queries for select(), insert(), update(), delete(), etc:
$db = Zend_Registry::get('db');
$select = $db->select()
->from('posts')
->where('cat_id = ?', $catId)
->order('date_posted DESC')
->limit(5);
$rows = $db->fetchAll($select);
希望这会有所帮助.干杯!
Hope this helps. Cheers!
这篇关于Zend_Db 没有 Zend 框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Zend_Db 没有 Zend 框架
基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何替换eregi() 2022-01-01
