php mysqli删除数据的方法:1、创建一个PHP示例文件;2、通过mysqli_connect连接mysql;3、通过“delete from emp4 where id=$id”语句删除指定数据即可。
本文操作环境:Windows7系统、PHP7.1、Dell G3电脑。
php mysqli怎么删除数据?
PHP MySQLi删除数据记录示例
代码如下:
<?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); ?>
推荐学习:《PHP视频教程》