Home >Backend Development >PHP Problem >How to delete data in php mysqli
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.
#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 = 'localhost:3306'; $user = 'root'; // MySQL用户账号 $pass = ''; $dbname = 'test'; $conn = mysqli_connect($host, $user, $pass,$dbname); if(!$conn){ die('Could not connect: '.mysqli_connect_error()); } echo 'Connected successfully<br/>'; $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!