blog.Ring.idv.tw

PHP Data Objects (PDO) 介紹

PHP Data Objects (PDO) 介紹


PHP Data Objects

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;

2007-10-10 10:28:07

Leave a Comment

Copyright (C) Ching-Shen Chen. All rights reserved.

::: 搜尋 :::

::: 分類 :::

::: Ads :::

::: 最新文章 :::

::: 最新回應 :::

::: 訂閱 :::

Atom feed
Atom Comment

::: 人氣指數 :::

今日人氣:198

累積人氣:3096038


::: 線上人數 :::

counter