ZendFramework transaction processing problems

Source: Internet
Author: User
An official example of ZendFramework transaction processing is provided as follows: & lt ;? Php // & nbsp; create an & nbsp; $ db object and start a transaction. $ db-& gt; beginTransaction (); // & nbsp; try database operations. // & nbsp; if successful, the com Zend Framework transaction processing problem
An official example is provided as follows:
 
// Create a $ db object and start a transaction.
$ Db-> beginTransaction ();

// Try database operations.
// If the operation succeeds, commit the operation;
// Assume that roll back.
Try {
$ Db-> query (...);
$ Db-> commit ();
} Catch (Exception $ e ){
$ Db-> rollBack ();
Echo $ e-> getMessage ();
}

?>


The instance I wrote does not pass, but prompts
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

Seems to be prompting that a transaction is already running? I am not familiar with ZF just a moment ago. paste the relevant source file.

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 [the Common folder, which is the same as the controllers folder and models folder]

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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.