View Discussion
Improve Article
Save Article
View Discussion
Improve Article
Save Article
To delete a file by using PHP is very easy. Deleting a file means completely erase a file from a directory so that the file is no longer exist. PHP has an unlink[] function that allows to delete a file. The PHP unlink[] function takes two parameters $filename and $context. Syntax:
unlink[ $filename, $context ];
Below programs illustrate the above approach: Program 1: This program uses unlink[] function to remove file from directory. Suppose there is a file named as “gfg.txt”
php
Output:
gfg.txt has been deleted
Program 2: This program uses unlink[] function to delete a file from folder after using some operation.
php
Output:
Warning: unlink[] expects parameter 1 to be a valid path, resource given in C:\xampp\htdocs\server.php on line 12 Resource id #3 cannot be deleted due to an error
Note: If the file does not exist then it will display an error.
PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.
- Trang chủ
- Hướng dẫn học
- Học PHP
- MySQL delete
MySQL delete
- Khi cần xóa dữ liệu nào đó không cần thiết, ta có thể sử dụng câu lệnh
DELETE
trong MySQL để thực hiện việc xóa. Các bước thực hiện:
- Kết nối database và table.
- Xác định record [hàng] cần xóa.
- Xử lý dữ liệu.
- Đóng database.
Cấu trúc delete:
tên_table
: là tên bảng được chọn xem dữ liệu.tên_cột
: là tên các cột có trong table.giá_trị_cột_cần_xóa
: giá trị nhận biết record [hàng] cần xóa.
Xóa dữ liệu
Kiểu hướng đối tượng
Ứng với điều
kiện WHERE id=1
, tương ứng với record [hàng] thứ 1, tất cả dữ liệu của record này sẽ bị xóa.
Kiểu thủ tục
Download file ví dụ
Trong file download đã có sẵn file tintuc.sql, file này là file dữ liệu mẫu, sau khi đã tạo database chúng ta có thể đưa dữ liệu từ file tintuc.sql bằng thao tác import có trong phpMyAdmin.