Codeigniter - 事务测试模式不起作用

发布于 2024-12-04 20:07:51 字数 792 浏览 2 评论 0 原文

那么我做错了什么?当我运行以下代码时,即使事务处于测试模式,数据库也始终会更新。

/**
 * 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;
}

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江湖正好 2024-12-11 20:07:51

AbhishekDilliwal 在他的评论中为我们提供了答案。如果他发布答案,我将删除我的答案并接受他的答案,这样他就会代替我获得荣誉。


答:

Codeigniter 事务测试模式目前不起作用。


解决方案:

替换

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

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

将以下 codeigniter 系统文件中的:

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

::看起来像 rommelxcastro 提交了 已修复 github 存储库。现在我们只需要等待 Codeigniter 拉取它并发布新版本:)


来源:

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:

错爱 2024-12-11 20:07:51

您是否尝试过用纯 SQL 编写查询,而不是使用像 where() 和 update() 这样的库函数?我对此不确定,但 CI 文档仅显示文档中的 query() 函数。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文