强制mysql-php抛出事务错误

时间:2015-05-20 13:45:04

标签: php mysql codeigniter transactions

我正在使用php-codeigniter。我创建了一个事务代码。我想检查我的事务错误处理代码是否有效,因此我想故意在第二个查询($ addNewQuery)中抛出一个事务错误。可能吗?我怎么能这样做?

$this->db->trans_start();
        if($m_arrPostValues['replaceFlag'] == true) {
            $this->_deleteAllCategoryFromProduct($m_arrPostValues['categoryId']);
        }
        $addNewQuery = "
        insert into t_productcategory(a_categoryid,a_productid,a_createddate,a_createdby)
        select ".$m_arrPostValues['categoryId'].",?,now(),?
        from dual
        where not exists (select a_categoryproductid from t_productcategory where a_categoryid= ".$m_arrPostValues['categoryId']." and a_productid = ?)";
        foreach($m_arrPostValues['arrIds'] as $product) {
            $this->db->query($addNewQuery,array($product,$user,$product));
        }
        $this->db->trans_complete();

        if($this->db->trans_status() === FALSE) {
            echo 'Transaction Error';exit;
        }

0 个答案:

没有答案