ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

$this->db->update() - a cautionary tale

December 12, 2008 1:18pm

Subscribe [1]
  • #1 / Dec 12, 2008 1:18pm

    if you’re ever tempted to do something like this

    $data = array(
        'password' => $new_password
    );
    $where = array(
        'username' => $user_name,
        'account_no' => $account_no
    );
    $this->db->where($where);
    $this->db->update('table1',$data);
    $this->db->update('table2',$data);

    DON’T!

    db->update resets your where statement… I’ve just had the most frantic five minutes of my life, almost wiped out 15,000 users. good job it was a dev copy of the db, but bricks were well and truly sh*t.

    might be worth mentioning this is in the docs. (in 48 point red, bold)

  • #2 / Dec 12, 2008 3:54pm

    gstjohn

    23 posts

    Well, I wouldn’t say it’s obvious enough or even in a place that would be expected, but you will find the following located at http://ellislab.com/codeigniter/user-guide/database/active_record.html under ‘Active Record Caching’:

    While not “true” caching, Active Record enables you to save (or “cache”) certain parts of your queries for reuse at a later point in your script’s execution. Normally, when an Active Record call is completed, all stored information is reset for the next call. With caching, you can prevent this reset, and reuse information easily.

    FYI, Active Record Caching is probably the solution you need.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases