I have a table items
with id
as primary key, and two more fields activatedby
and active
.
CREATE TABLE `items`. ( `id` BIGINT NOT NULL AUTO_INCREMENT , `active` BOOLEAN NOT NULL DEFAULT FALSE , `activatedby` BIGINT NOT NULL DEFAULT '0' , PRIMARY KEY (`id`)) ENGINE = InnoDB;
The script gets an array with 100 entries with an id-number and 1 or 0 for active or not active. [$id,1] or [$id,0]
. activatedby
should always be set to the same $userid
.
Being a beginner I a natural query would look to me like
UPDATE items (id, active, activatedby)
VALUES
('622057', 1, '17389551'),
('2913659', 0, '17389551'),
and so on .....
('6160230', 1, '17389551')
My problem, I just restarte writing in php a bit after years, and because getting suggested to use prepared statements and binding parameters, how this binding would work on such an UPDATE statement? (If my not tested statement is valid at all.)
But even more I worry about speed, as in the same thread and in the php documentation I read preparing statements could cause much overhead, and it might be MUCH faster to use multi_query
and mysqli_real_escape_string
instead.
I don't like the binding syntax at all, and would anyway prefere to use mysqli_real_escape_string
, but even less I would like to use an old method that probably will be deprecated sometimes.
Just to boil my question down: 1. multi_query or the syntax above? 2. prepared statements and binding or using mysqli_real_escape_string
?