Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter事务不工作_Php_Mysql_Codeigniter - Fatal编程技术网

Php Codeigniter事务不工作

Php Codeigniter事务不工作,php,mysql,codeigniter,Php,Mysql,Codeigniter,我有一个将行插入表的函数,如下所示 function fn_insert_user() { $this->db->trans_begin(); $this->db->query('INSERT INTO user VALUES(9,"john", "9865321245")'); $this->db->query('INSERT INTO user VALUES(8,"martin", "8865321245")'); $thi

我有一个将行插入表的函数,如下所示

function fn_insert_user() {
    $this->db->trans_begin();
    $this->db->query('INSERT INTO user VALUES(9,"john", "9865321245")');
    $this->db->query('INSERT INTO user VALUES(8,"martin", "8865321245")');
    $this->db->trans_complete();

    if ($this->db->trans_status() === FALSE)
    {
        $this->db->trans_rollback();
        echo 'something bad happened';
    }
    else
    {
        $this->db->trans_commit();
        echo 'everything is fine';
    }

}
现在主键8已经存在,因此正如预期的那样,它不应该允许插入第二个查询(这很好)

它成功地回滚了第一个查询,但问题是它打印的不是“发生了什么不好的事情”

A Database Error Occurred
Error Number: 1062
Duplicate entry '8' for key 'PRIMARY'
INSERT INTO user VALUES(8,"martin", "8865321245")
Filename: C:\wamp\www\landmark\system\database\DB_driver.php
Line Number: 330
如果你这样做

$this->db->trans_complete();

然后它将提交事务两次

您有两种解决方案:

    $this->db->trans_start();
    $this->db->query('QUERY');
    $this->db->trans_complete();

    if ($this->db->trans_status() === FALSE)
    {
        echo "fail";
    } 

更多详情见文件

如果你这样做

$this->db->trans_complete();

然后它将提交事务两次

您有两种解决方案:

    $this->db->trans_start();
    $this->db->query('QUERY');
    $this->db->trans_complete();

    if ($this->db->trans_status() === FALSE)
    {
        echo "fail";
    } 

更多详情见文件

如果你这样做

$this->db->trans_complete();

然后它将提交事务两次

您有两种解决方案:

    $this->db->trans_start();
    $this->db->query('QUERY');
    $this->db->trans_complete();

    if ($this->db->trans_status() === FALSE)
    {
        echo "fail";
    } 

更多详情见文件

如果你这样做

$this->db->trans_complete();

然后它将提交事务两次

您有两种解决方案:

    $this->db->trans_start();
    $this->db->query('QUERY');
    $this->db->trans_complete();

    if ($this->db->trans_status() === FALSE)
    {
        echo "fail";
    } 


更多详情见文件

这不是交易问题

试试看:

function fn_insert_user() {

    $this->db->trans_begin();
    $this->db->query('INSERT INTO user VALUES("john", "9865321245")');
    $this->db->query('INSERT INTO user VALUES("martin", "8865321245")');
    $this->db->trans_complete();

    if ($this->db->trans_status() === FALSE)
    {
        $this->db->trans_rollback();
        echo 'something bad happened';
    }
    else
    {
        $this->db->trans_commit();
        echo 'everything is fine';
    }

}

这不是交易问题

试试看:

function fn_insert_user() {

    $this->db->trans_begin();
    $this->db->query('INSERT INTO user VALUES("john", "9865321245")');
    $this->db->query('INSERT INTO user VALUES("martin", "8865321245")');
    $this->db->trans_complete();

    if ($this->db->trans_status() === FALSE)
    {
        $this->db->trans_rollback();
        echo 'something bad happened';
    }
    else
    {
        $this->db->trans_commit();
        echo 'everything is fine';
    }

}

这不是交易问题

试试看:

function fn_insert_user() {

    $this->db->trans_begin();
    $this->db->query('INSERT INTO user VALUES("john", "9865321245")');
    $this->db->query('INSERT INTO user VALUES("martin", "8865321245")');
    $this->db->trans_complete();

    if ($this->db->trans_status() === FALSE)
    {
        $this->db->trans_rollback();
        echo 'something bad happened';
    }
    else
    {
        $this->db->trans_commit();
        echo 'everything is fine';
    }

}

这不是交易问题

试试看:

function fn_insert_user() {

    $this->db->trans_begin();
    $this->db->query('INSERT INTO user VALUES("john", "9865321245")');
    $this->db->query('INSERT INTO user VALUES("martin", "8865321245")');
    $this->db->trans_complete();

    if ($this->db->trans_status() === FALSE)
    {
        $this->db->trans_rollback();
        echo 'something bad happened';
    }
    else
    {
        $this->db->trans_commit();
        echo 'everything is fine';
    }

}

已插入enrty
8
。请检查数据库截断表并尝试使用完整的新条目。是的,我知道,但由于它导致错误,它应该已打印错误“发生了不好的事情”,并且不是常见的代码点火器错误。已插入enrty
8
。请检查数据库截断表并重试使用完整的新条目。是的,我知道,但当它导致错误时,它应该打印错误“发生了不好的事情”和不常见的codeigniter错误。已插入enrty
8
。请检查数据库截断表并尝试使用完整的新条目。是的,我知道,但当它导致错误时,它应该已打印错误“发生了不好的事情”和不常见的codeigniter错误已插入enrty
8
。请检查您的数据库截断您的表并尝试使用完整的新条目。是的,我知道这一点,但当它导致错误时,应该打印错误“发生了不好的事情”,而不是常见的codeigniter错误