catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

Multi insert performs differently since v1.5.* #728

Closed kuofp closed 6 years ago

kuofp commented 6 years ago

// v1.4.5 did the trick, while v1.5.* raised an error
// ErrorException Undefined index: col
$db = new \Medoo\Medoo([
    'database_type' => 'mysql',
    'database_name' => 'test',
    'server'        => 'test',
    'username'      => 'test',
    'password'      => 'test',
    'charset'       => 'utf8',
]);

$db->query('
    CREATE TEMPORARY TABLE `demo`(
        `id` INT NOT NULL,
        `col` INT NOT NULL,
        PRIMARY KEY(`id`)
    )
')->fetchAll();

$arr = [
    ['id' => 1],
    ['col' => 2],
];

$db->insert('demo', $arr);
catfan commented 6 years ago

The $arr should be

$arr = [
    'id' => 1,
    'col' => 2
];

or

$arr = [
    [
        'id' => 1,
        'col' => 2
    ],
    [
        'id' => 2,
        'col' => 1
    ]
];