简体   繁体   中英

why can't i use insert_batch like this in codeigniter

hi i am using codeigniter , i use the insert_batch function . i have a table structure like this

在此处输入图片说明

an i am using an array like this to insert_batch function

Array
(
    [0] => Array
        (
            [ProfileID] => 5
            [ActivityTypeID] => 4
            [ActivityTitle] => bbggg
            [ActivityLink] => http://localhost/elephanti2/home/user/action/settings/user/profilesettings
            [IsActive] => 1
            [CreatedOn] => 1331532905
            [CreatedBy] => 5
        )

    [1] => Array
        (
            [ActivityImage] => 
            [ActivityTitle] => kkkkkkkk
            [ActivityFromDate] => 1330642800
            [ActivityToDate] => 1331852400
            [ActivityDescription] => kkkkkkkkkkkkkkkk
            [ActivityLink] => 
            [CreatedOn] => 1331532905
            [CreatedBy] => 5
            [ProfileID] => 5
            [ActivityTypeID] => 1
        )

)

error is given

在此处输入图片说明

why this happens

can't i use arrays with different keys ???????

please help.............. thanks in advance

insert_batch translations into a SQL query that uses the VALUES form of INSERT . This requires every item being inserted to specify the same fields.

I have fixed my issue after change the line of code in the file "system\\database\\DB_query_builder.php"

Replace the code in the the file DB_query_builder.php, Path : "system\\database\\DB_query_builder.php"

protected function _insert_batch($table, $keys, $values)
{
return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values);
}

By below code

protected function _insert_batch($table, $keys, $values)
{
if(is_array($values))
{
$values = implode(',',$values);
}
return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values);
}

I have resolved my issue by this way. hope, same will work for you.

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