Welcome Guest, Not a member yet? Register   Sign In
insert_batch returning -1 when query fails
#1

I'm trying to work with the query builder's insert_batch function. According to the documentation, it should return FALSE on failure. That is not the case.

Try this controller method:
PHP Code:
    public function barf() {
        
$data = array(
                array(
                        
'title' => 'My title',
                        
'name' => 'My Name',
                        
'date' => 'My date'
                
),
                array(
                        
'title' => 'Another title',
                        
'name' => 'Another Name',
                        
'date' => 'Another date'
                
)
        );
        
$retval $this->db->insert_batch("i_do_not_exist"$data);
        
var_dump($retval);
    } 

Seems to me it should probably throw an exception and at the very least it should return false.
Reply
#2

Note insert_batch will also return -1 if you attempt to insert a record with a duplicate primary key value.
Reply
#3

Also, the documentation on update_batch is incorrect:
http://www.codeigniter.com/userguide3/da...date_batch
It lists the third param as this:
Code:
$value (string) – Field value, if $set is a single field
In the code, it's different:
Code:
    /**
     * Update_Batch
     *
     * Compiles an update string and runs the query
     *
     * @param    string    the table to retrieve the results from
     * @param    array    an associative array of update values
     * @param    string    the where key
     * @return    int    number of rows affected or FALSE on failure
     */
    public function update_batch($table, $set = NULL, $index = NULL, $batch_size = 100)
    {
        // blah blah blah
    {
Reply
#4

Do you have to post this on 3 different places?
Reply
#5

I really apologize. I was trying to implement something with it and was casting around for help. Kinda had my head up my rear.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB