Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Database Field Error CodeIgniter

I am getting the following error message in CodeIgniter 2.1:

A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: database/DB_active_rec.php

Line Number: 1407

I'm trying to update fields in my database. I have this code and every tutorial are just the same for batch upload. It works anyway but the thing is it display such an error.

this what i have in my model:

function update2($data){
   $this->db->update_batch('users',$data, "id");
}

This what i have in my controller:

public function updateValues(){
    $this->load->model('get_db');
    $newRow = array(
        array(
            'id' => '3',
            'firstname' => 'Rapphie'
        ),
        array(
            'id' => '2',
            'firstname' => 'Charmie'
        )
    );
    $this->get_db->update2($newRow);
    echo "it has been updated";
}
like image 590
Charmie Avatar asked Jul 01 '12 03:07

Charmie


1 Answers

Just realized that using a foreach like M_A_K suggested actually beats the purpose of using the update_batch function. This is because by using foreach, we're actually doing single update (not batch) for each array elements. This is no different than using the (single) update function in CodeIgniter.

like image 200
Amir Syafrudin Avatar answered Nov 17 '22 15:11

Amir Syafrudin