Home > Backend Development > PHP Tutorial > PHP+MySQL delete operation instance, phpmysql delete instance_PHP tutorial

PHP+MySQL delete operation instance, phpmysql delete instance_PHP tutorial

WBOY
Release: 2016-07-13 10:09:28
Original
896 people have browsed it

PHP+MySQL delete operation instance, phpmysql delete instance

The example in this article describes the use skills of PHP+MySQL deletion operation. Share it with everyone for your reference. The details are as follows:

Copy code The code is as follows:

Delete record


//Parameters for connecting to the database
$host = "localhost";
$user = "root";
$pass = "zq19890319";
$db = "phpdev";
//Create mysqli object
//Open a database connection
$mysqli = new mysqli($host, $user, $pass, $db);
//Check connection errors
If(mysqli_connect_errno()){
die("Unable to connect!");
}  
//If the record ID exists, perform the delete operation
If(isset($_GET['id'])){
//Construct SQL to delete records
$query = "DELETE FROM symbols WHEREid = ".$_GET['id'];
                                                                            //Execute SQL query
If($mysqli->query($query)){
//Display the number of records affected by deletion
echo $mysqli->affected_rows. "row(s) affected";
                                                                                                                          else  
                                                                                   //If there is no matching record, display the error message returned by the database
echo "Error in query : $query. ".$mysqli->error;
                                                                                                              }  
//Construct and display deleted records
$query = "SELECT * FROM symbols";
//Execute the query
If($result=$mysqli->query($query)){
//Display the number of rows in the returned record set
If($result->num_rows>0){
//If there is a record
//Display the contents of the record set columns
echo "";
​​​​​​while($row=$result->fetch_array()){
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
                                                                                                                                                                                                                                              //Release the memory occupied by the object
         $result->close();
}  
else else

//Output database error information
echo "Error in query: $query. ".$mysqli->error;
}  
//Close database
$mysqli->close();
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/945698.htmlTechArticlePHP+MySQL deletion operation example, phpmysql deletion example. This example describes the use skills of PHP+MySQL deletion operation. Share it with everyone for your reference. The details are as follows: Copy the code The code is as follows...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
".$row[0]."".$row[1]."".$row[2]."Delete