Home > Mobile >  Can't fetch URL from database Wordpress
Can't fetch URL from database Wordpress

Time:11-01

Hi everyone in the database a column called attachments stores data like this

"a:3:{s:6:\"saveTo\";s:7:\"wpmedia\";s:14:\"attachmentType\";s:6:\"images\";s:11:\"attachments\";a:1:{i:0;a:6:{s:12:\"attachmentId\";i:176165;s:4:\"file\";s:68:\"https://www.yallamission.com/wp-content/uploads/2022/10/MG_00283.jpg\";s:8:\"fileName\";s:12:\"MG_00283.jpg\";s:9:\"thumbnail\";s:76:\"https://www.yallamission.com/wp-content/uploads/2022/10/MG_00283-150x150.jpg\";s:8:\"fileSize\";s:9:\"292.85 KB\";s:8:\"fileType\";s:10:\"image/jpeg\";}}}

i need to fetch the image url only yet i am unable to do it successfully as i don't understand this format

I tried to use php functions and substr() yet the text before and after has dynamic content and no fixed standard.

CodePudding user response:

This is serialized data and you can unserialize them and access the attachments by using unserialize($variable) and access the attachment elements.

CodePudding user response:

Use json_encode instead of serialize when building the data for INSERTing. Then use the JSON functions in SQL (if your MySQL is new enough).

  • Related