delete_all.php
<?php
//Config
$server = "localhost";
$user = "root";
$password = "";
$database = "address_book";
//Establishing a Connection to MySQL Server
$connection = mysqli_connect($server, $user, $password, $database);
//Check Connection
if (!$connection) {
die("<h2>Total Fail</h2> " . mysqli_connect_error());
} else {
echo "Connection Successfull <br>";
}
//SQL Command
$sql_command = "TRUNCATE TABLE people";
if (mysqli_query($connection, $sql_command)) {
echo "SQL Command OK";
} else {
echo "SQL Error " . mysqli_error($connection) ;
}
?>
This SQL command will delete all the data from the people
table in the connected database.
The TRUNCATE TABLE
command is used to delete all rows from a table while keeping its structure intact. So, in this case, the table structure (columns and data types) will still be there, but all the data will be deleted.
If the command is successful, it will output "SQL Command OK", otherwise it will output "SQL Error" along with the error message generated by MySQL.
When we run it, all rows are gone.
Connection Successfull
SQL Command OK
No comments:
Post a Comment