Articles

PHP MySQL - DROP

PHP MySQL - DROP


Let’s discuss how to delete the entire table  in MYSQL through PHP  in the XAMPP Server.

Consider the table - treatments present in the database - hospital snapshot with existing record.

 

 

DROP in MySQL is used to delete all the rows from a table along with schema (columns).

 

SQL DROP- Syntax

 

DROP TABLE TABLE_NAME;

Approach:

1.Specify the credentials to create a connection object.
The credentials include XAMPP Server localhost name, username, password and database name.
$connecting_data =  new mysqli($server, $user, $pwd, $data);

2.Specify the SQL Query that includes DROP
$my_query = DROP TABLE TABLE_NAME;

3.Query to check whether ll the records are deleted or not.
if ($connecting_data->query($my_query) === TRUE) {
  echo "Table Truncated Succesfully!!.";
} else {
  echo "Error: " . $connecting_data->error;
};

4.Close the connection object
$connecting_data->close();

Example:

In this example, we will delete the treatmentsTable using DROP.

<?php

// Specify the server
$server = "localhost";

// Specify the user
$user = "root";

// Specify the password
$pwd = "";

// Specify the database 
$data = "hospital";

// Let's create connection by using the above details
$connecting_data =  new mysqli($server, $user, $pwd, $data);

$my_query = "DROP TABLE treatments";


if ($connecting_data->query($my_query) === TRUE) {
  echo "treatments dropped Succesfully!!.";
} else {
  echo "Error: " . $connecting_data->error;
}

$connecting_data->close();
?>

Output:

Let's check in XAMPP:

So, we can see that entire table is deleted.

 

Conclusion:

In this tutorial, we seen how  to delete the  table through PHP Script using DROP in XAMPP Server.

 


PHP MySql

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Gottumukkala Sravan Kumar 171FA07058
B.Tech (Hon's) - IT from Vignan's University. Published 1400+ Technical Articles on Python, R, Swift, Java, C#, LISP, PHP - MySQL and Machine Learning
Page Views :    Published Date : Jun 14,2024  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!