I want to reset my ids from 1 to the max one because, since I need to update a table many times, I risk to have ids greater than the maximum value for the ID
column.
For example, sometimes I get the ID 2842719402837
that is too big to be entered in my ID
column (INTEGER, length 11).
I use this query to reset the ids from 1 to the max one :
SET @num := 0;
UPDATE riepilogo SET id = @num := (@num+1);
ALTER TABLE riepilogo AUTO_INCREMENT =1;
Here you can find the answer whence I got the SQL : Click Here
While it's working perfectly on phpMyAdmin, it's not working with PHP.
I'm using this code to execute the query :
$sql = "SET @num := 0;
UPDATE riepilogo SET id = @num := (@num+1);
ALTER TABLE riepilogo AUTO_INCREMENT =1;";
$result = $conn->query($sql);
if(!$result) die("MySQL Error : ".$sql."<br>Error : ".$conn->error);
Naturally I already set the $conn
variable, but I'm getting the following error :
MySQL Error : SET @num := 0; UPDATE riepilogo SET id = @num := (@num+1); ALTER TABLE riepilogo AUTO_INCREMENT =1;
Error : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UPDATE riepilogo SET id = @num := (@num+1); ALTER TABLE riepilogo AUTO_' at line 2
So, this query is working with the SQL console of phpMyAdmin, but it's not executing it with PHP.
What am I doing wrong? Thanks a lot!