Zend Framework 事务处理 有关问题

WBOY
發布: 2016-06-13 12:59:53
原創
1786 人瀏覽過

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 />
?>
登入後複製


我写的实例中,确没有通过,而是提示
Fatal error: Uncaught exception 'PDOException' with message 'There is already an active transaction' in E:\php\ZendFramework\library\Zend\Db\Adapter\Pdo\Abstract.php:305 Stack trace: #0 E:\php\ZendFramework\library\Zend\Db\Adapter\Pdo\Abstract.php(305): PDO->beginTransaction() #1 E:\php\ZendFramework\library\Zend\Db\Adapter\Abstract.php(484): Zend_Db_Adapter_Pdo_Abstract->_beginTransaction() #2 D:\svnrepos\WiClub\src\application\models\shop.php(76): Zend_Db_Adapter_Abstract->beginTransaction() #3 D:\svnrepos\WiClub\src\application\controllers\ShopController.php(507): shop->inserttest(Array) #4 E:\php\ZendFramework\library\Zend\Controller\Action.php(513): ShopController->shopaddtestAction() #5 E:\php\ZendFramework\library\Zend\Controller\Dispatcher\Standard.php(289): Zend_Controller_Action->dispatch('shopaddtestActi...') #6 E:\php\ZendFramework\library\Zend\Controller\Front.php(946): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #7 D:\svnrepos\WiC in E:\php\ZendFramework\library\Zend\Db\Adapter\Pdo\Abstract.php on line 305

似乎是提示已经有一个事务在运行?刚接触ZF不久,不太熟悉,把相关源文件贴上来吧

config.ini
<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 />
登入後複製


Util.php    [所在文件夹 Common,与controllers文件夹,models文件夹同级]

<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>
登入後複製
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板