The examples in this article describe the techniques used for PHP+MYSQL deletion operations. Share to everyone for your reference. Specifically as follows:
Copy Code code as follows:
<?php
Parameters for connecting to a database
$host = "localhost";
$user = "root";
$pass = "zq19890319";
$db = "Phpdev";
Creating Mysqli Objects
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, the delete operation is performed
if (Isset ($_get[' id ')) {
To construct the SQL for deleting records
$query = "DELETE from symbols Whereid =". $_get[' id '];
Execute SQL query
if ($mysqli->query ($query)) {
Show the number of records affected after deletion
Echo $mysqli->affected_rows. "Row (s) affected";
}
Else
{
If there are no matching records, the error message returned by the database is displayed
echo "Error in Query: $query." $mysqli->error;
}
}
Constructs a record that appears deleted
$query = "SELECT * from symbols";
Execute the query
if ($result = $mysqli->query ($query)) {
Shows the number of rows returned from the recordset
if ($result->num_rows>0) {
If there is a record
Display the contents of a column in a recordset
echo "<table cellpadding=10 border=1>";
while ($row = $result->fetch_array ()) {
echo "<tr>";
echo "<td>". $row [0]. " </td> ";
echo "<td>". $row [1]. " </td> ";
echo "<td>". $row [2]. " </td> ";
echo "<td><a href=". $_server[' php_self '. "mce_href=". $_server[' Php_self ']. " Id= ". $row [0]." > Delete </a></td> ";
echo "</tr>";
}
}
Frees the memory occupied by an object
$result->close ();
}
Else
{
Output Database error information
echo "Error in Query: $query." $mysqli->error;
}
Close Database
$mysqli->close ();
?>
I hope this article will help you with your PHP program design.