开发者

Codeigniter - Transaction Test Mode Not Working

开发者 https://www.devze.com 2023-04-05 00:50 出处:网络
So what am I doing wrong? When I run the following开发者_运维技巧 code, the database is always updated even though transactions is in test mode.

So what am I doing wrong? When I run the following开发者_运维技巧 code, the database is always updated even though transactions is in test mode.

/**
 * update_batch
 * This updates multiple rows. The data array must include the game_id and game_type_prize_id
 * @param array
 * @return bool
 * @author zechdc
 */
function update_batch($data)
{
    $result = TRUE;

    foreach($data as $prize)
    {
        $this->db->trans_start(TRUE); //first param is set to TRUE for test mode.
        $this->db->where('game_id', $prize['game_id']);
        $this->db->where('game_type_prize_id', $prize['game_type_prize_id']);
        $this->db->update('game_prizes', $prize);
        $this->db->trans_complete();

        if($this->db->affected_rows() == -1)
        {
            $result = FALSE;
        }
    }


    return $result;
}


AbhishekDilliwal provided us with the answer in his comments. If he posts the answer I will delete mine and accept his so he gets credit instead of me.


Answer:

Codeigniter Transactions Test Mode Currently Does Not Work.


Solution:

Replace:

$this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;

with:

$this->_trans_status = ($test_mode === TRUE) ? FALSE : $this->_trans_status;

in the following codeigniter system files:

system/database/drivers/mysql/mysql_driver.php
system/database/drivers/mysqli/mysqli_driver.php
system/database/drivers/oci8/oci8_driver.php
system/database/drivers/odbc/odbc_driver.php
system/database/drivers/postgre/postgre_driver.php
system/database/drivers/sqlite/sqlite_driver.php

It looks like rommelxcastro submitted the fix to the github repo already. Now we just have to wait for Codeigniter to pull it and release a new version :)


Sources:

  • Abhishek Dilliwal's comment
  • https://github.com/EllisLab/CodeIgniter/issues/5
  • https://github.com/rommelxcastro/CodeIgniter/commit/6f4ffeb35fdc06024c63de0fc929566140b8176a


Have you tried writing your queries in plain SQL, rather than using the library functions like where() and update()? I'm not sure on this, but the CI docs only show the query() function in the docs.

http://codeigniter.com/user_guide/database/transactions.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号