I am going through an older php application with some functional issues. I came across the following code that appears to be designed to reset the ids in a table:
SET @num := 0;
UPDATE `pop_table` SET id = @num := (@num+1);
ALTER TABLE `pop_table` AUTO_INCREMENT =1;
So… what in the world is an ‘:=’ operator for?? – and what would be the alternative in this particular snippet?
I’ve searched here, php.net, google, apparently “:=” is either to small or too obscure to find, or I just don’t know how to commit a proper search for it. Thanks for any thoughts.
This is not PHP Code. It’s MySQL.
This is a MySQL Function with
which means that the value
0is assigned to the variable@num(refer to the MySQL Manual)This is used in
UPDATE pop_table SET id = @num := (@num+1);To make it more understandable, the PHP equivalent would be:
$num = 0;(this is not really comparable, just to get the idea)UPDATE
I was inspired by the comments to do the NOT RECOMMENDED PHP solution.
didn’t test it, but should work.