开发者

Delete a database record and associated image

开发者 https://www.devze.com 2023-03-21 14:37 出处:网络
I have a table of photos like this: photo_id, photo_url, user_id When I want to delete a photo, I need to delete the row in the table and the photo on the server. So to do this, I need to do 2 quer

I have a table of photos like this:

photo_id, photo_url, user_id

When I want to delete a photo, I need to delete the row in the table and the photo on the server. So to do this, I need to do 2 queries:

  1. A SELECT query to return the photo's url and delete it with unlink()
  2. a DELETE query to delete 开发者_JAVA百科the row in the table

Is a simpler way to do this, perhaps using only one query?


Your way the best way to do this....How can it be simpler....

Also, if your photos use ids then you may just delete the row instead of selecting the query to return to the photos URL. then if this is successful proceed with deleting the thumbnail

0

精彩评论

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