I have an InndoDB table
CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL,
`network_id` int(10) unsigned NOT NULL,
`nickname` varchar(20) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `network_id` (`network_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
In php I receive (it does not matter where from) an array $network_info
, which contains pairs network_id
,nickname
. For those network_id
which are present in users
I would like to update their nickname
. For those, which are not present I would like to insert them into table with generated (new incremented) id
.
Earlier, I have used id
as AUTO_INCREMENT, but queries such as INSERT IGNORE
and so on, increment it all time, even when insertion was not done,and it is not good.
Which is the best way to solve this problem?