insert or replace data / on duplicate key update for multiple insert

Flachag
Member | 2
+
0
-

Hey,

I use Nette Database and I didn't find how to use “on duplicate key update” for multiple insert:

I use multiple insert like this:

  $database->query('insert into machines (id, name, latitude, longitude)',$machinesData, 'ON DUPLICATE KEY UPDATE', [
            'name' => '###' ,
            'latitude' => '###',
            'longitude' => '###' ,
            'address' => '###' ,
            'zipcode' => '###'
        ]);

I don't know what I'm supposed to put for the duplicate key. In SQL I would do like this:

insert into machines (id ,name, latitude, longitude) values
	(?,?,?,?)
on duplicate key update
			id=VALUES(id),
            name=VALUES(name),
            latitude=VALUES(latitude),
            longitude=VALUES(longitude)";

Someone know how to do the same thing with nette Database ?

dsar
Backer | 53
+
0
-

Look here

Last edited by dsar (2020-11-16 16:17)

Flachag
Member | 2
+
0
-

Thanks ! I find a solution too:

 $database->query('insert into machines',$machinesData,
"on duplicate key update
name=values(name),
latitude=values(latitude),
longitude=values(longitude),
address=values(address),
zipcode=values(zipcode)");