Zend DB原子事务
问题描述:
我必须执行一组SQL操作,它们要么一起存在要么一起死亡。 因此,如果我的语句的任何部分失败,整个过程将回滚到开始,就好像事务从未发生过一样。Zend DB原子事务
没有zend的,我会做:
$conn->query('BEGIN');
$conn->query($myQuery);
//rollback if anything went wrong
$conn->query('COMMIT');
在Zend的我创造了我的引导数据库连接:
protected function _initDb()
{
$config=Zend_registry::get('config');
$db = Zend_Db::factory($config->resources->db->adapter, $config->resources->db->params);
//set default adapter
Zend_Db_Table_Abstract::setDefaultAdapter($db);
Zend_Registry::set("db", $db);
}
而且使用DB交互由模型类(扩展Zend_Db_Table_abstract)
制成class Platform extends Zend_Db_Table_Abstract
{
public function insertPlatform($x)
{
$this->insert($x);
}
}
class Game extends Zend_Db_Table_Abstract
{
public function insertGame($x)
{
$this->insert($x);
}
}
我怎么能达到相同的(生存到在一起Zend的一起吗?
感谢
卢卡
答
Zend_Db的包装交易功能了。所以在使用或不使用ZF时没有什么不同。
您发现在Adapter Section of the Zend_Db Manual中解释的ZF交易。查找段落“控制数据库事务”。