Php+mysql Delete operation instance, phpmysql Delete instance
The examples in this article describe the use of php+mysql delete operations. Share to everyone for your reference. Specific as follows:
Copy the Code code as follows:
Deleting records
<?php
Parameters for connecting to a database
$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, the delete operation is performed
if (Isset ($_get[' id ')) {
Constructing SQL to delete 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
{
Displays the error message returned by the database if there are no matching records
echo "Error in Query: $query.". $mysqli->error;
}
}
Construct to display deleted records
$query = "SELECT * from symbols";
Execute the query
if ($result = $mysqli->query ($query)) {
Shows the number of recordset rows returned
if ($result->num_rows>0) {
If there is a record
Display the contents of columns in a recordset
echo "
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/945698.html www.bkjia.com true http://www.bkjia.com/PHPjc/945698.html techarticle Php+mysql Delete operation instance, Phpmysql Delete instance This article describes the use of the php+mysql delete operation. Share to everyone for your reference. As follows: Copy code code such as ...
"; while ($row = $result->fetch_array ()) {echo "
"; echo "
". $row [0]." | "; echo "
". $row [1]." | "; echo "
". $row [2]." | "; echo "
Delete | "; echo "
"; }}//Releases the memory occupied by the object $result->close (); } else {//Output database error message echo "Error in Query: $query.". $mysqli->error; }//Close database $mysqli->close ();?>