2007-12-22 23:37
ringtail
Zend Framework中对Oracle的操作简单操作总结
呵呵,自己blog上写的,摘了部分,贴过来希望有高手指教。
原文地址:[url=http://blog.xmulib.org/ringtail/2007/12/zend-frameworkoracle.html]http://blog.xmulib.org/ringtail/2007/12/zend-frameworkoracle.html[/url]
2.插入数据
无论是DB还是Table类,都使用insert()方法。
对于Oracle来说,如果要使用sequence作为自增的主键的话,需要使用trigger。
比如,有tag表,主键为tagid,其对应的sequence为tag_seq,要插入数据时,需要先新建trigger:
create or replace trigger tag_tri
before insert on tag
for each row
declare
nextid number;
begin
IF :new.tagid IS NULL or :new.tagid=0 THEN
select tag_seq.nextval
into nextid
from sys.dual;
:new.tagid:=nextid;
end if;
end tag_tri;
其余部分和插入其它数据库相同
[php]<?php
$table_name='TAG';
$row = array (
'TAGNAME' => $tagname,
'TAGTOTAL' => '1'
);
$this->db->insert($table_name,$row);
?>[/php]
3.更新数据
3.1直接执行update语句,参见文档。
3.2如果update语句中,有包含数据库的特殊关键字时,需要先将数据选出,然后再更新
[php]<?php
$where = $this->db->quoteInto('tagname = ?',$tagname);
//如果只取一行的话,用fetchRow()就可以了
$rowset = $this->tag->fetchAll($where);
$count=$rowset->count();
$tag = $rowset->current();
if($count!=0){
$tagid=$tag->TAGID;
//tagtotal+1
$tag->TAGTOTAL ++; //应判断一下当前用户是否
$tag->save();
}
?>[/php]
4.删除数据
[php]<?php
//删除已有的collect表中记录
// where条件语句
$where = $this->db->quoteInto('USERID = ?', $userid)
.$this->db->quoteInto('AND LINKID = ?', $linkid);
// 删除数据并得到影响的行数
$rows_affected = $this->collect->delete($where);
?>[/php]
总结完毕:
tips:
注意表名、字段名等的大小写!