I'm trying to create a MySQL event so that I can have files automatically added to my MySQL database. Basically, I'm running an XAMPP server right now so all my website/database associated image files are inside the 'C:\\Users\\Mus\\server\\htdocs\\images' directory. Whenever I put an image file into this directory; I need this file to be uploaded to the database automatically via this MySQL event which I'm trying to create. This means that the database needs to keep checking for new files at time intervals of say 5 seconds and if a new file has been added to said directory, a new entry will be automatically created for the image (within a specified table) and at the same time, the image will then be uploaded to that very same table within the database.
The SQL code I've used so far is:
CREATE EVENT 'eventnov' ON SCHEDULE EVERY 5 SECOND STARTS '2015-10-27 00:00:00' ENDS '2015-10-28 00:00:00' DO INSERT INTO 'images_11_nov' SELECT NOW();
I realize lines 5 and 6 are probably completely wrong but I've tried researching existing problems and I've found no luck. I've looked at the official MySQL documentation and unfortunately I can't find anything relevant to my specific problem. I don't know the syntax to have MySQL do all the following within a single MySQL event:
Could someone help me finish off the above code to perform these necessary functions? If I need to provide more information, please do let me know and I shall oblige.
CREATE EVENT 'eventnov' ON SCHEDULE EVERY 5 SECOND STARTS '2015-10-27 00:00:00' ENDS '2015-10-28 00:00:00' SELECT count(*) 'images_11_nov' system(ls C:\\Users\\Mus\\server\\htdocs\\images | wc -l) system(ls -t | head -1) DO INSERT INTO 'images_11_nov';
Yes it is very ease. You have to do following task.
select count(*) table_name;
use the system command on your mentioned directory
system(ls C:\\Users\\Mus\\server\\htdocs\\images | wc -l)
This will give you the number of files available in mentioned directory.
Now compare this count with the count of database and check both are equal or not.
If it is increased by 1 the run simple system command to know the latest added file in directory.
system(ls -t | head -1)
Here ls -t will list the files by time and pipe with head will give you the name of latest added file.
I hope this will help you.
Regards, Jayesh Dhandha
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.