阅读量: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
,否则会输出错误信息。最后,记得关闭数据库连接。