开发者

delete file using MySQL procedure

Is there any way to delete file using SQL command ?

I have image files in filesystem, and links to them in DB. For example:

CREATE TABLE products (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    name TINYTEXT NOT NULL,
    category INT UNSIGNED NOT NULL,
    FOREIGN KEY (category) REFERENCES categories(id) ON DELETE CASCADE,
    ............
) ENGINE=InnoDB;
CREATE TABLE images (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    img_link TINYTEXT, /*path and name of JPG/PNG file*/
    product INT UNSIGNED NOT NULL,
    FOREIGN KEY (product) REFERENCES products(id) ON DELETE CASCADE,
    ............
) ENGINE=InnoDB;  

When categ开发者_JAVA技巧ory\product deleted, deletes the links of images that belong to the deleted category\product. (becouse 'ON DELETE CASCADE')

But I need to delete the files itself too. Something like:

CREATE TRIGGER del BEFORE DELETE ON images FOR EACH ROW CALL delete_file(OLD.img_link);

Of course its possible to create table of all files that must be deleted. I ask if is there any way to do it at real-time.

Thanks


You can't do this from within MySQL. The only things it can do to affect files are create new ones as part of a SELECT ... INTO OUTFILE ... query. There's no facilities for manipulating external files, let alone deleting them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜