This article mainly introduces the methods for deleting PHP + MySQL, and analyzes the tips for deleting MySQL information. It has some reference value. For more information, see
This article mainly introduces the methods for deleting PHP + MySQL, and analyzes the tips for deleting MySQL information. It has some reference value. For more information, see
This article describes how to use PHP + MySQL to delete objects. Share it with you for your reference. The details are as follows:
The Code is as follows:
Delete record
<? Php
// Database connection Parameters
$ Host = "localhost ";
$ User = "root ";
$ Pass = "zq19890319 ";
$ Db = "phpdev ";
// Create a mysqli object
// Open a database connection
$ Mysqli = new mysqli ($ host, $ user, $ pass, $ db );
// Check for connection errors
If (mysqli_connect_errno ()){
Die ("Unable to connect! ");
}
// If the record ID exists, delete it.
If (isset ($ _ GET ['id']) {
// Construct the SQL statement for deleting records
$ Query = "delete from symbols WHEREid =". $ _ GET ['id'];
// Execute SQL query
If ($ mysqli-> query ($ query )){
// Display the number of affected records after deletion
Echo $ mysqli-> affected_rows. "row (s) affected ";
}
Else
{
// If no matching record exists, the error message returned by the database is displayed.
Echo "Error in query: $ query.". $ mysqli-> error;
}
}
// Create and display deleted records
$ Query = "SELECT * FROM symbols ";
// Execute this query
If ($ result = $ mysqli-> query ($ query )){
// Display the number of returned Record Sets
If ($ result-> num_rows> 0 ){
// If a record exists
// Display the content of columns in the record set
Echo"
I hope this article will help you with php programming.
";While ($ row = $ result-> fetch_array ()){Echo"
";Echo"
". $ Row [0]." | ";Echo"
". $ Row [1]." | ";Echo"
". $ Row [2]." | ";Echo"
Delete | ";Echo"
";}}// Release the memory occupied by the object$ Result-> close ();}Else{// Output database error informationEcho "Error in query: $ query.". $ mysqli-> error;}// Close the database$ Mysqli-> close ();?>