I want to update multiple rows in the database with codeigniters update_batch()
function.
But the field specified in the where should also be changed.
The following code should make it clear:
$set = array(
array(
'token' => '65787131678754',
'device' => 'none',
'new_token_value' => ''
),
array(
'token' => '75798451315464',
'device' => 'none',
'new_token_value' => ''
)
);
$this->db->update_batch(TBL_NAME, $set, 'token');
Tokens specified in token
should be updated with device
to 'none'
and the token
itself should be set to empty string ''
.
Is this possible with update_batch()
function?
In sql I would write something like
UPDATE TBL_NAME
SET token='', device='none'
WHERE token='65787131678754'
for one update but this is not practicable for multiple, so I want to use the update_batch()
function.
I created a helper function mostly identical to the codeigniter
batch_update()
function.But with the ability to update the index itself. The new value is defined by
index_update_key
.Now I can do the following
and the sql output is