Welcome Guest, Not a member yet? Register   Sign In
updateBatch(): Argument #2 ($index) must be of type string
#1

(This post was last modified: 03-11-2024, 01:58 PM by ramonpuig.)

Hello!

I am getting this exception :

CodeIgniter\Database\BaseBuilder::updateBatch(): Argument #2 ($index) must be of type ?string, array given
My code is this , its in a function inside my model.

PHP Code:
$db $this->db;

    $builder $db->table($this->table);
    $builder->updateBatch($data,['date','name''winner_name','runnerUp_name''titleAvgEloRating''matchID']); 
In the CI4 documentation the example :
PHP Code:
$data = [
    [
        'title'  => 'Title 1',
        'author' => 'Author 1',
        'name'  => 'Name 1',
        'date'  => 'Date 1',
    ],
    [
        'title'  => 'Title 2',
        'author' => 'Author 2',
        'name'  => 'Name 2',
        'date'  => 'Date 2',
    ],
];
$builder->updateBatch($data, ['title''author']); 


Does not appear to show second argument as a String, but as an array. I am doing something wrong? Or is there a bug here?
Reply
#2

Upgrade CI4.


Quote:Since v4.3.0, the second parameter $index of updateBatch() has changed to $constraints. It now accepts types array, string, or RawSql.
https://codeigniter4.github.io/CodeIgnit...pdatebatch
Reply
#3

(This post was last modified: 03-12-2024, 05:29 AM by ramonpuig.)

(03-11-2024, 05:40 PM)kenjis Wrote: Upgrade CI4.


Quote:Since v4.3.0, the second parameter $index of updateBatch() has changed to $constraints. It now accepts types array, string, or RawSql.
https://codeigniter4.github.io/CodeIgnit...pdatebatch

i updated to 4.4.6 and i will test but i cant get any further until i solve another bug that has appeared after the update, not happening before the update.

Code:
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        parent::initController($request, $response, $logger);

       
        $this->session = \Config\Services::session();

ErrorException:

Attempt to read property "driver" on null

I am loading the session in the bascontroller but no luck

(03-12-2024, 04:34 AM)ramonpuig Wrote:
(03-11-2024, 05:40 PM)kenjis Wrote: Upgrade CI4.


Quote:Since v4.3.0, the second parameter $index of updateBatch() has changed to $constraints. It now accepts types array, string, or RawSql.
https://codeigniter4.github.io/CodeIgnit...pdatebatch

i updated to 4.4.6 and i will test but i cant get any further until i solve another bug that has appeared after the update, not happening before the update.

Code:
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        parent::initController($request, $response, $logger);

       
        $this->session = \Config\Services::session();

ErrorException:

Attempt to read property "driver" on null

I am loading the session in the bascontroller but no luck

I was able to solve the issue by adding the session.php to the App/Config folder , i had not checked this was a requirement in the upgrade!
Reply
#4

See https://codeigniter4.github.io/CodeIgnit...ading.html
Reply




Theme © iAndrew 2016 - Forum software by © MyBB