问题
I have a db table:
ConfigID | Type | Key | Value
--------------------------------------------------------------
0 | "API" | "ClientID" | "iofoewi"
1 | "API" | "ClientSecret" | "eijfoiewjfioejfoiewjfoie"
Take the following code:
$data = array(
array(
'Key' => "ClientID",
'Value' => $testAPICredential->ClientID
),
array(
'Key' => "ClientSecret",
'Value' => $testAPICredential->ClientSecret
)
);
try
{
$this->context->db->trans_start();
$this->context->db->update_batch( $this->tableName, $data, "Key" );
$this->context->db->trans_complete();
return ($this->context->db->trans_status() === FALSE)? FALSE:TRUE;
}
catch( Exception $e )
{
return FALSE;
}
It outputs this SQL when I use the profiler:
UPDATE `config` SET `Value` = CASE
WHEN `Key` = 'ClientID' THEN 'iofoewi2'
WHEN `Key` = 'ClientSecret' THEN 'eijfoiewjfioejfoiewjfoie2'
ELSE `Value` END WHERE `Key` IN ('ClientID','ClientSecret')
And yet the database table is un=touched?
Any ideas?
回答1:
If you are using CI 3.1.2 maybe it's will help you.
In our project. We find out that function update_patch sometimes will be have problem. Index for update sometimes will be wrong. So i found out another function for replace is update_batch_real_index In file /yourproject/system/database/DB_query_builder.php
From time using this to present is 3 months we not found any bug again. Maybe you should try that.
来源:https://stackoverflow.com/questions/22254999/codeigniter-update-batch-is-not-working