Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7399663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:05:24+00:00 2026-05-29T04:05:24+00:00

I am trying to use the update_batch() function from the Active Record helper in

  • 0

I am trying to use the update_batch() function from the Active Record helper in Codeigniter as follows:

var_dump($data);
$this->db->where('event_id',$data['event_id']);
$this->db->update_batch('results',$data['results'],'uid');
echo $this->db->last_query();

This prints out the following:

array(2) {
  ["event_id"]=>
  string(2) "11"
  ["results"]=>
  array(2) {
    [0]=>
    array(2) {
      ["uid"]=>
      string(36) "1beab26d-f705-11e0-a190-f46d048dfd25"
      ["res"]=>
      string(1) "2"
    }
    [1]=>
    array(2) {
      ["uid"]=>
      string(36) "9dcc9e0a-bf24-11e0-838c-f46d048dfd25"
      ["res"]=>
      string(1) "1"
    }
  }
}
UPDATE results SET res = CASE 
WHEN uid = '1beab26d-f705-11e0-a190-f46d048dfd25' THEN '2'
WHEN uid = '9dcc9e0a-bf24-11e0-838c-f46d048dfd25' THEN '1'
ELSE res END WHERE `event_id` = '11' AND uid IN ('1beab26d-f705-11e0-a190-f46d048dfd25','9dcc9e0a-bf24-11e0-838c-f46d048dfd25')

Obviously, this is a large security hole because the field and table names are not being escaped from the update_batch section (although they are escaped in the where section). Am I doing something wrong? This behaviour is not specified in the docs:

http://codeigniter.com/user_guide/database/active_record.html#update

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:05:24+00:00Added an answer on May 29, 2026 at 4:05 am

    Uhm, according to the documentation for the update_batch() function, they just claim that

    “values are automatically escaped producing safer queries”

    with these words, I see implied that fields and table names are not protected.

    But in the “queries” page, they kind of contradict by saying:

    In many databases it is advisable to protect table and field names –
    for example with backticks in MySQL. Active Record queries are
    automatically protected, however if you need to manually protect an
    identifier you can use:

    $this->db->protect_identifiers(‘table_name’);

    And IIRC it’s true, AR always wraps names in backticks (that’s why you need to pass FALSE, usually, to the active record method if you don’t want escaping to mess with your query part).

    EDIT:

    Uhm, I just went rapidly over the code, and it looks like it is escaped:

    // Batch this baby
    for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100)
    {
       $sql = $this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where);
    
       $this->query($sql);
    }
    

    So, migth really be a bug; So far, if your table names aren’t dynamically generated, you can simply ignore this and be safe anyway; or you could run the protect_identifiers() method and do that yourself (wrong in principle, but hey…).

    You can try and reproduce the bug more than once, and then file a bug report

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use jQuery's ajax functionality to update data from a web
I am trying to use this MySQL query: SET @a:=0; UPDATE tbl SET sortId=@a:=@a+1
I'm trying to use this code: UPDATE media_items SET content_url = replace(content_url,’cd%20images’,'my%20music’); And I
I'm trying to update a package in Oracle, coming from SQL Server this has
I was trying to use record update for an existential record when I ran
I am trying to use PHP to update column data but I am receiving
I am trying to use batch updates in Access VBA. My code works fine
I am trying to use an update query to update the first 3 characters
I am trying to use an update trigger in SQL Server 2000 so that
I am trying to use an xmlpoke task to update a VS Project File

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.