欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

Zend Framework 事务处理 有关问题

程序员文章站 2022-03-08 19:36:52
...
Zend Framework 事务处理 问题
官方给出一个示例,如下:

// 创建一个 $db对象, 然后开始做一个事务处理.
$db->beginTransaction();

// 尝试数据库操作.
// 假如成功,commit该操作;
// 假如, roll back.
try {
$db->query(...);
$db->commit();
} catch (Exception $e) {
$db->rollBack();
echo $e->getMessage();
}

?>


我写的实例中,确没有通过,而是提示
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

[general]
db.adapter = PDO_MYSQL
db.config.host = localhost
db.config.username = root
db.config.password = 123456
db.config.dbname = testdb
db.config.charset = utf8
date_default_timezone = "PRC"


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

require_once 'Zend/Config/Exception.php';
require_once 'Zend/Config/Ini.php';
require_once 'Zend/Registry.php';
require_once 'Zend/Db.php';
require_once 'Zend/Db/Table.php';
//require_once 'common/Blowfish.php';
//require_once 'common/Hosts.php';
class Common_Util
{
public static function getDb($configName,$setcharset=false)
{
if($configName)
{
$config=new Zend_Config_Ini('../config.ini',$configName);
$registry= Zend_Registry::getInstance();
$registry->set('config',$config);
$params=$config->db->config->toArray();
$params['options']=array(PDO::ATTR_PERSISTENT => true);
$db = Zend_Db::factory($config->db->adapter,$params);
Zend Framework 事务处理 有关问题

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频