在 CodeIgniter 中,
是否可以创建事务(尚未提交)并获取ID,并生成if语句,如果语句是< strong>true,那么它会被commit?
不同的函数可以得到相同的交易?
例如:
$newID = $this->model->create();
if(!empty($newID)) {
$this->model->commit();
}else{
// cancel commit;
}
最佳答案
您可以尝试手动运行交易。
可以遵循:
$this->db->trans_begin();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->query('AND YET ANOTHER QUERY...');
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
}
else
{
$this->db->trans_commit();
}
阅读 docs 了解更多信息。
关于php - 从数据库创建并获取新 ID 但尚未提交 CodeIgniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28655309/