Rumah > Artikel > pembangunan bahagian belakang > Zend Framework 事务处理 有关问题
Zend Framework 事务处理 问题
官方给出一个示例,如下:
<?php<br /> <br /> // 创建一个 $db对象, 然后开始做一个事务处理.<br /> $db->beginTransaction();<br /> <br /> // 尝试数据库操作.<br /> // 假如成功,commit该操作;<br /> // 假如, roll back.<br /> try {<br /> $db->query(...);<br /> $db->commit();<br /> } catch (Exception $e) {<br /> $db->rollBack();<br /> echo $e->getMessage();<br /> }<br /> <br /> ?>
<br /> [general]<br /> db.adapter = PDO_MYSQL<br /> db.config.host = localhost<br /> db.config.username = root<br /> db.config.password = 123456<br /> db.config.dbname = testdb <br /> db.config.charset = utf8<br /> date_default_timezone = "PRC"<br />
<br> <?php <br /> require_once 'Zend/Config/Exception.php';<br> require_once 'Zend/Config/Ini.php';<br> require_once 'Zend/Registry.php';<br> require_once 'Zend/Db.php';<br> require_once 'Zend/Db/Table.php';<br> //require_once 'common/Blowfish.php';<br> //require_once 'common/Hosts.php';<br> class Common_Util<br> { <br> public static function getDb($configName,$setcharset=false)<br> {<br> if($configName)<br> {<br> $config=new Zend_Config_Ini('../config.ini',$configName);<br> $registry= Zend_Registry::getInstance();<br> $registry->set('config',$config);<br> $params=$config->db->config->toArray();<br> $params['options']=array(PDO::ATTR_PERSISTENT => true);<br> $db = Zend_Db::factory($config->db->adapter,$params); <div class="clear"> </div>