// Connect to the MySQL database $conn = mysqli_connect('localhost', 'username', 'password', 'database_name'); // Delete a record $id = 1; $sql = "DELETE FROM users WHERE id = $id"; mysqli_query($conn, $sql); // Close the database connection mysqli_close($conn);
// Connect to the MySQL database $conn = mysqli_connect('localhost', 'username', 'password', 'database_name'); // Delete multiple records $ids = [1, 2, 3]; $sql = "DELETE FROM users WHERE id IN (" . implode(',', $ids) . ")"; mysqli_query($conn, $sql); // Close the database connection mysqli_close($conn);In this example, we use the IN operator to delete multiple records at once. We first connect to the MySQL database and then build the SQL statement dynamically using the implode() function to merge the IDs of the records to delete. We then execute the statement using mysqli_query() and close the database connection. Package/Library: Database operations in PHP can be done using built-in functions or with database abstraction libraries like Doctrine ORM, Laravel's Eloquent ORM, or Symfony's Doctrine DBAL.