English 中文(简体)
《刑法》中的积极记录
原标题:Update using Active Record in CodeIgniter

我有一个奇怪的问题,也许我不明白,积极记录如何充分发挥作用,但这里是这样。 我试图以某种方式更新记录。 简单易懂和测试Im只是直接供应,而不是变数。

现在,如果我正确理解“积极记录”,它的工作似乎与我用在阿普时的工作截然不同。 采用实体框架管理网。 但我的理解是,你可以先从一行选择记录,然后在下行更新时,将更新这一记录。 这至少是它如何看待文件。 The example from the docs:

$data = array(
                title  => $title,
                name  => $name,
                date  => $date
            );

$this->db->where( id , $id);
$this->db->update( mytable , $data); 

因此,我试图在我的法典中做同样的事情:

        $updateData = array(
            description  =>  My localhost 
        );

        $this->myDb->where( id , 2832);
        $this->db->update( Users , $updateData);

确实,这根本就不像预期的那样发挥作用! 它实际上更新了该数据库,但它更新了每个记录,以便所有记录都更新到“My localhost”的描述领域。 I m仍在使用测试数据库。

我在《评论》中看到,通过在更新说明中提供补贴,也存在一种替代办法:

$this->db->update( Users , $updateData, array( id  => 2832));

这一工作非常出色。 但...... 我仍然想知道,第一种选择为什么不奏效,因为如果我不理解,我可能会在数据库中造成其他破坏性错误......

我真的希望能澄清这项工作,以及为什么所有记录都得到更新。

最佳回答
$updateData = array(
     description  =>  My localhost 
);

$this->myDb->where( id , 2832);
$this->db->update( Users , $updateData);

This is not working because you are applying the "where" clause to $this->myDb and then calling update on $this->db. Since there are no restrictions on $this->db all records are getting updated.

Change it to:

$this->db->where( id , 2832);
$this->db->update( Users , $updateData);
问题回答

暂无回答




相关问题
Codeigniter WHERE on "AS" field

I have a query where I need to modify the selected data and I want to limit my results of that data. For instance: SELECT table_id, radians( 25 ) AS rad FROM test_table WHERE rad < 5 ORDER BY rad ...

Problem find joined table in rails

I have model represent association rule (Body => Head) def Item has_many :heads has_many :bodies ... end def Rule has_many :heads has_many :bodies ... end def Body belongs_to :item belongs_to :rule ...

FreeTDS Bad token from the server (SQL Server)

Today we had a lot more activity than normal between our Ruby on Rails application and our remote legacy SQL Server 2005 database, and we started getting the error below intermittently. What is is? ...

Castle ActiveRecord: one-to-one

While playing around with one-to-one associations in castle activerecord I stumbled upon the following problem: I m trying to model a one-to-one relationship (user-userprofile in this case). I ...

Sending email updates: model or observer?

I have an Event model, which stores an event feed for each user. I also need to email the updates to users which have enabled email notifications in their profile. From an architectural point of view,...

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

热门标签