Php+mysql Delete operation instance _php tips

Source: Internet
Author: User
Tags mysql delete

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.