There is alre-6ren">
gpt4 book ai didi

mysql - Zend 框架提示 "There is already an active transaction"

转载 作者:行者123 更新时间:2023-11-29 01:11:48 25 4
gpt4 key购买 nike

我们正在使用 zend_db_table,但由于 Zend Framework 提示两个事务处于事件状态,我们遇到了一些问题:

[message:protected] => There is already an active transaction
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /var/www/vhosts/test.local/private/library/Zend/Db/Adapter/Pdo/Abstract.php
[line:protected] => 305
[trace:Exception:private] => Array

这是 Controller 中的代码:

     public function convertAction()
{
$this->setNoRender();

// If the quote is a copy of a previous one, fetch all the datas
$quoteId = Zend_Filter::filterStatic($this->getRequest()->getParam('qte_id'), 'int');
$quoteTable = new Model_QuotesTable();
$quoteRow = $quoteTable->findById($quoteId);
if (count($quoteRow)) {
$clonedId = $quoteRow->convertToJob();
$this->flashMessageRedirect('Quotation successfully converted', '/jobs/edit/job_id/' . $clonedId);
} else {
$this->flashMessageRedirect('Unable to find the quote to be converted', '/quotes');
}
}

在扩展 zend_db_table_abstract 的 QuotesTableRow 中调用这个函数:

    public function convertToJob()
{
$db = $this->_getTable()->getAdapter();
$db->beginTransaction();

$jobsTable = new Model_JobsTable();

try {

/*
* Update the status of the old row to match the $status passed into this function
*/
$this->qte_status = "Accepted";
$this->save();

/*
* Create new row with the same details as above
*/

$newRow = $jobsTable->createRow();

$newRow->job_title = $this->qte_title;
$newRow->job_cus_id = $this->qte_cus_id;
$newRow->job_enq_id = $this->qte_enq_id;
$newRow->job_qte_id = $this->qte_id;
$newRow->job_title = $this->qte_title;
$newRow->job_description = $this->qte_description;
$newRow->job_work_location_id = $this->qte_work_location_id;
$newRow->job_work_category_id = $this->qte_work_category_id;
$newRow->job_work_type_id = $this->qte_work_type_id;
$newRow->job_cus_code = $this->qte_cus_code;
$newRow->job_cus_name = $this->qte_cus_name;
$newRow->job_wt_ref_code = $this->qte_wt_ref_code;
$newRow->job_wt_description = $this->qte_wt_description;
$newRow->job_wl_code = $this->qte_wl_code;
$newRow->job_wl_description = $this->qte_wl_description;
$newRow->job_wc_ref_code = $this->qte_wc_ref_code;
$newRow->job_wc_description = $this->qte_wc_description;
$newRow->job_qte_title = $this->qte_title;
$newRow->job_datetime_created = date('Y-m-d H:i:s');

$newRowId = $newRow->save();

$db->commit();
return $newRowId;
}
catch (Exception $e) {
$db->rollback();

echo('<pre>');
print_r($e);
echo('</pre>');
exit();

throw new Exception($e->getMessage());
return false;
}
}

此外,它似乎与我们不在的模型有关,因为如果我们使用与 Model_JobsTable() 相关的 save() 函数注释该行,脚本正在运行,而当我们注释时它返回相同的错误另一个保存()。

最佳答案

此错误是从 MySQL 返回的,ZF 只是告诉您错误消息。

您是否在同一个请求中启动两个事务?这可以解释为什么您会收到此错误消息,或者您可能在事务中间有一个中止的连接并且它没有回滚或自动提交。

您应该只为每个数据库连接启动一个事务。如果您需要两个模型在单个请求中有一个事件事务,那么您需要获得 2 个独立的数据库连接。

参见 this (great) answer Bill Karwin 就此问题提出的意见。

您可以运行查询 SHOW ENGINE InnoDB STATUS; 来获取事件事务的列表。如果您有一个打开的并且没有来自 PHP/ZF 的事件事务,请尝试关闭该事务,否则您将不得不查看您的代码并查看两个事务如何在同一请求中启动。

关于mysql - Zend 框架提示 "There is already an active transaction",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11782023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com