Home >Backend Development >PHP Problem >How to delete data in php mysqli

How to delete data in php mysqli

藏色散人
藏色散人Original
2021-09-20 09:13:352514browse

php Mysqli method of deleting data: 1. Create a PHP sample file; 2. Connect to mysql through mysqli_connect; 3. Delete the specified data through the "delete from emp4 where id=$id" statement.

How to delete data in php mysqli

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

php mysqli How to delete data?

PHP MySQLi Delete Data Record Example

The code is as follows:

<?php 
$host = &#39;localhost:3306&#39;; 
$user = &#39;root&#39;;  // MySQL用户账号
$pass = &#39;&#39;; 
$dbname = &#39;test&#39;; 
 
$conn = mysqli_connect($host, $user, $pass,$dbname); 
if(!$conn){ 
  die(&#39;Could not connect: &#39;.mysqli_connect_error()); 
} 
echo &#39;Connected successfully<br/>&#39;; 
 
$id=2; 
$sql = "delete from emp4 where id=$id"; 
if(mysqli_query($conn, $sql)){ 
 echo "Record deleted successfully"; 
}else{ 
echo "Could not deleted record: ". mysqli_error($conn); 
} 
 
mysqli_close($conn); 
?>

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to delete data in php mysqli. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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