PREZI PREZI - 5 months ago 12
PHP Question

Using the multi query function to modify table after clear button is clicked

$DBConnect = @mysqli_connect("localhost", "username", "password")

$query = "DELETE FROM hitcounter";

$query = "ALTER TABLE hitcounter AUTO_INCREMENT=0";

if (isset($_POST['clear']))

{

(mysqli_multi_query($DBConnect,$query))

// I made a hit counter which displays hits on page

// Only thing i have left is the reset button that switch the pages hits to 0 after the clear button is pressed

// I am unable to execute the query

}

Answer

You can use:

$query = "TRUNCATE TABLE hitcounter;"

Which will delete all rows and reset the auto_increment to 0 as well in only one query.

EDIT:

This does not work for InnoDB tables as long they have a relationship