php - 从数据库创建并获取新 ID 但尚未提交 CodeIgniter

标签 php database codeigniter commit autocommit

在 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/

相关文章:

python - PostgreSQL:创建扩展 plpythonu 查询在 Ubuntu 19.10 和 PostgreSQL 10.10 上不起作用

php - CodeIgniter View 中应包含多少代码?

mysql - Codeigniter - 数据库选择

php - 为什么ajax在php中复制整个页面

php 希腊字符编码

sql - 在 Reporting Services 中使用存储过程

database - 文件夹搜索算法

javascript - Ajax 调用无法与 onclick 一起使用

php - 联系表单脚本未运行,白页

php - PHP header() 和 exit() 会在重定向之前安全地终止脚本吗?