PHP mysql_query()函数用于删除表中数据记录。
由于PHP5.5版本起,不推荐使用mysql_query(),建议使用以下2种方法

mysqli_query()
PDO::_query()

示例

  • 01
  • 02
  • 03
  • 04
  • 05
  • 06
  • 07
  • 08
  • 09
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
<?php $host = 'localhost:3306'; $user = 'root'; $pass = ''; $dbname = 'mydb'; $conn = mysqli_connect($host, $user, $pass, $dbname); if(!$conn) { die('Could not connect :'.mysqli_error()); } echo "Connected successfully<br/>"; $id = 2; $sql = "delete from `emp5` where `id` ='".$id."'"; if(mysqli_query($conn,$sql)) { echo "Record deleted successfully"; }else{ echo "Could not delete record:".$mysqli_error($conn); } mysqli_close($conn); ?>

执行上述代码,结果如下

  • 01
  • 02
Connect successfully Record deleted successfully