Welcome Guest, Not a member yet? Register   Sign In
Determine if CodeIgniter’s Model Save() is Insert or Update
#2

(This post was last modified: 12-28-2020, 05:15 AM by 68thorby68.)

I have been playing with this functionality.

If I use
PHP Code:
$this->getInsertID() 
instead of
PHP Code:
insertID() 
CI does not throw an error.

I've checked the DB and all seems in order.

Therefore it looks like I can use the save() function to insert and update, and return the insert id when an insert is performed.

PHP Code:
public function addEditData($vals) {
        if($this->save($vals)) {
            log_message('notice''[SUCCESS] {file}-{line}, Data Saved - '.session('user_name'));
            
            
if($insertID=$this->getInsertID()) {
                return $insertedID;
            }else{
                return true;
            }
            
        
}else{
            log_message('notice''[ERROR] {file}-{line}, Failed to Add/Edit Data - '.session('user_name'));
            return false;
        }
    

I have been playing with this functionality.

If I use
PHP Code:
$this->getInsertID() 
instead of
PHP Code:
insertID() 
CI does not throw an error.

I've checked the DB and all seems in order.

Therefore it looks like I can use the save() function to insert and update, and return the insert id when an insert is performed.

PHP Code:
public function addEditData($vals) {
        if($this->save($vals)) {
            log_message('notice''[SUCCESS] {file}-{line}, Data Saved - '.session('user_name'));
            
            
if($insertID=$this->getInsertID()) {
                return $insertedID;
            }else{
                return true;
            }
            
        
}else{
            log_message('notice''[ERROR] {file}-{line}, Failed to Add/Edit Data - '.session('user_name'));
            return false;
        }
    
Reply


Messages In This Thread
RE: Determine if CodeIgniter’s Model Save() is Insert or Update - by 68thorby68 - 12-28-2020, 05:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB