2009年12月25日 星期五

Zend FrameWork的交易

$this->db->beginTransaction();

try {

//執行SQL語法

$this->db->insert('dbname' , array('欄位1' => '值1'));
$this->db->insert('dbname' , array('欄位2' => '值2'));
$this->db->insert('dbname' , array('欄位3' => '值3'));
$this->db->commit();//成功就執行
}catch (Zend_Db_Exception $e){
$this->db->rollback();//失敗就回去上一步
throw $e;

}

2009年12月13日 星期日

PHP的框架及ORM框架

PHP框架

CoreMVC官方網站
CodeMVC_google

fleaphp

ThinkPHP

CakePHP

CodeIgniter


EasyFramework


戲法人人會變,看你喜歡用哪一種摟

最近在看阿六文章

有段玩笑話說
使用Zend就像加入共產黨
FleaPHP像是改革開放
ThinkPHP開始實施共產主義
所有都試過後發現無黨派的最自由

PHP的ORM框架

doctrine

ZendFramework資料庫的設置

ZendFramework設定資料庫時config.ini,跟ROR一樣有個專門的設定檔

[general]
db.adapter=PDO_MYSQL //使用PDO的MySQL接口
db.config.host=localhost //MySQL的主機IP
db.config.username=root //填入資料庫的使用者
db.config.password= //填入資料庫的密碼
db.config.dbname=zendoophp //填入使用的資料庫名稱



然後在單一進入點的index.php
註冊這組設定
$config=new Zend_Config_Ini('./application/config/config.ini',null, true);
Zend_Registry::set('config',$config);

$dbAdapter=Zend_Db::factory($config->general->db->adapter,
$config->general->db->config->toArray());

設定資料庫接口從Zend_Db::factory(接口,設定陣列);

$dbAdapter->query('SET NAMES UTF8');
先送出一個SQL,將資料庫的連線語系設定為中文