The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. Each database driver that implements the PDO interface can expose database-specific features as regular extension functions. Note that you cannot perform any database functions using the PDO extension by itself; you must use a database-specific PDO driver to access a database server.
其實和JDBC是同樣的意思,兩者都是抽象層的產物,意指為提供了一致性的介面來存取資料庫,這在移植不同的資料庫時是相當方便的。
PECL4WIN,這裡提供了Windows平臺的擴充下載,當你要使用Zend_Db來連結資料庫時,請務必下載PDO的DLL檔,並設定php.ini才行。
PostgreSQL範例
設定php.ini
extension=php_pdo.dll
extension=php_pdo_pgsql.dll
Zend_Db程式片段
$params = array ( 'host' => 'localhost', 'username' => 'postgres', 'password' => '****', 'dbname' => 'MyDB' ); $db = Zend_Db::factory('PDO_PGSQL', $params); $db->setFetchMode(Zend_Db::FETCH_OBJ); $result = $db->fetchAll('SELECT * FROM books'); $this->view->rs = $result;