zec*_*hdc 2 php activerecord transactions codeigniter
那么我做错了什么?当我运行以下代码时,即使事务处于测试模式,数据库也会始终更新.
/**
* 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;
}
Run Code Online (Sandbox Code Playgroud)
AbhishekDilliwal在他的评论中为我们提供了答案.如果他发布答案,我会删除我的并接受他,所以他得到了信用而不是我.
Codeigniter事务测试模式目前不起作用.
更换:
$this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
Run Code Online (Sandbox Code Playgroud)
有:
$this->_trans_status = ($test_mode === TRUE) ? FALSE : $this->_trans_status;
Run Code Online (Sandbox Code Playgroud)
在以下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
Run Code Online (Sandbox Code Playgroud)
看起来rommelxcastro已经将修复程序提交给了github repo.现在我们只需等待Codeigniter拉出它并发布新版本:)