【问题标题】:Check if stored procedure is still running in Codeigniter检查存储过程是否仍在 Codeigniter 中运行
【发布时间】:2018-12-19 05:47:52
【问题描述】:

我尝试使用此代码,但我调用的存储过程仍在数据库中运行,但在代码中它已经完成。

$this->db->trans_start();

$this->db->query('CALL sp_process();'); 

if ($this->db->trans_status() === FALSE) {# Something went wrong.

    $this->response->message[] = array(
            'message' => "Encountered a problem",
            'type' => 'error'
        );
} 
else {
    $this->db->trans_commit();
    $this->response->message[] = array(
        'message' => 'successfully processed',
        'type' => 'success'
    );
}
$this->db->trans_complete();

【问题讨论】:

  • $this->db->trans_begin(); $this->db->query('AN SQL QUERY...'); $this->db->query('另一个查询...'); $this->db->query('AND YET ANOTHER QUERY...'); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); } 其他 { $this->db->trans_commit(); }

标签: php mysql codeigniter stored-procedures


【解决方案1】:

来自Running Transactions Manually的文档:

手动运行时请务必使用$this->db->trans_begin() 交易,而不是$this->db->trans_start()

所以试着用$this->db->trans_begin();替换你的第一行

【讨论】:

  • 嗨,我试过这样做,但代码仍然没有与数据库同步。存储过程仍在进程列表中运行。
  • @Sheng 您可以尝试将呼叫$this->db->trans_complete(); 移到$this->db->query('CALL sp_process();'); 之后和状态检查之前吗?
  • @Sheng 不客气 :) 很抱歉,它没有解决问题。如果没问题,能否也加个存储过程定义的例子?
猜你喜欢
  • 1970-01-01
  • 2020-11-21
  • 2011-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多