Codeigniter update_batch is not working

Deadly 提交于 2020-01-17 01:34:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!