PHP delete语句的用法是什么

avatar
作者
猴君
阅读量:0

PHP中的delete语句用于从数据库中删除记录。其基本语法如下:

$servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB";  // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname);  // 检查连接 if ($conn->connect_error) {     die("Connection failed: " . $conn->connect_error); }  // 删除记录 $sql = "DELETE FROM tablename WHERE condition";  if ($conn->query($sql) === TRUE) {     echo "Record deleted successfully"; } else {     echo "Error deleting record: " . $conn->error; }  // 关闭连接 $conn->close(); 

在上面的代码中,DELETE FROM tablename WHERE condition 是删除记录的SQL语句。你需要将tablename替换为要删除记录的表名,将condition替换为符合要删除记录条件的条件语句。如果删除记录成功,将会输出Record deleted successfully,否则会输出错误信息。最后,记得关闭数据库连接。

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!