Zend_Db 的參數 (與 Zend_Config、Zend_Json)

::factory() 可以吃兩種語法,第一種是用兩個參數指定所有的資訊,像這樣:

$params = array('host' => 'localhost', 'username' => 'my_username', 'password' => 'my_password', 'dbname' => 'my_database');

$db = Zend_Db::factory('pdo_mysql', $params);

第二種是吃一個參數, (或者繼承他的 class):

$conf = Zend_Config_Ini('filename.ini');
$db = Zend_Db::factory($conf);

如果想把資料庫設定放在檔案裡,再用 Zend_Config 讀進來傳給 Zend_Db,目前官方有 兩種方法,不過這兩種方法我都不喜歡,用 找 "Zend_Config_Yaml",沒有什麼人在研究這個 (在是有看到一份,不過沒看到其他人用的心得)。

於是退而求其次,用 讀進來後用第一種方式傳進去。

Leave a Reply

Your email address will not be published. Required fields are marked *