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?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
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:
If you plan to use
Zend_Db_Table
, then you can make this the default adapter:In any case, it's helpful to have this adapter saved someplace where you can access it. For example:
Then in your downstream code, use this adapter to create queries for
select()
,insert()
,update()
,delete()
, etc:Hope this helps. Cheers!
For Zend Framework 2.*, creating the adapter would be:
To create select:
Or, if you want to get pure SQL from the $select:
Docs might be helpful. It can be even simpler if TableGateway is used.
Using Zend_Db would even be preferable (IMHO) over using Raw PDO. Just create a $db Object and then create SQL Statements using Zend_Db_Select Class and pass the $select SQL Statement to the fetch* (fetchRow, fetchAll...) Methods.