简体   繁体   中英

kohana -— auto insert

How to insert same data into database after update in ORM? For example i have function save() and inside this function i have update and it's working, but i don't know how to make insert with old update data. I mean it should make something like history in database. I only hope you can understand what i mean. Thanks for help.

public function save(Validation $validation = NULL)
{
    if ($this->loaded()) {
        // UPDATE TRIGGER

        DB::update($this->_table_name)
            ->set(array('ud_status' => 'D'))
            ->where('ud_status', '=', 'A')
            ->where('ud_uId', '=', $this->ud_uId)
            ->execute($this->_db);

        return false;
    } else {
        // INSERT TRIGGER
        return parent::save($validation);
    }
}
$query = DB::insert('users', array('username', 'password'))->values(array('fred', 'p@5sW0Rd'));

https://kohanaframework.org/3.3/guide/database/query/builder#insert

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM