CodeIgniter使用多个索引更新批处理

zbdgwd5y  于 2023-03-16  发布在  其他
关注(0)|答案(1)|浏览(124)

我在CodeIgniter上的活动记录更新批处理中遇到问题。
在文件上,

$this->db->update_batch('mytable', $data, 'title');

其中“title”是更新过程的索引。是否可以对此活动记录使用两个或多个索引?我已经尝试过了

$this->db->update_batch('mytable', $data, 'title, title_2');
$this->db->update_batch('mytable', $data, array('title', 'title_2');

但没有用。

vcudknz3

vcudknz31#

您可以在update_batch之前再提供一个where

$this->db->where( "title2", "some_title" );
$this->db->update_batch( "mytable", $data, 'title' );

然后,这将为update_batch查询提供额外的WHERE

WHERE title2 = 'some_title' AND title IN ( '...', '...', '...' );

但是,update_batch会在每次更新时内部重置WHERE子句。因此,作为一种解决方案,您可以事先将其分块,以确保WHERE在每次迭代时应用:

$chunks = array_chunk( $data, 100 );
foreach( $chunks as $chunk )
{
    $this->db->reset_query(); // To ensure there's no conflict/cache 
    $this->db->where( "title2", "some_title" );
    $this->db->update_batch( "mytable", $data, 'title' );
}

相关问题