PHP MySQL 删除记录
PHP mysql_query() 函数用于删除表中的记录。自从 PHP 5.5 版本开始, mysql_query() 函数已被废弃。现在推荐使用两个替代方法之一。
- mysqli_query()
- PDO::__query()
PHP MySQLi 删除记录示例
示例
<?php
host = 'localhost:3306';user = '';
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);
?>
输出:
Connected successfully
Record deleted successfully