Images/PHP and MySql? How does it work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mcc_shane
Forum Newbie
Posts: 22
Joined: Sat May 12, 2012 1:47 pm

Images/PHP and MySql? How does it work?

Post by mcc_shane »

Hi Everyone,

I'm not entirely sure how images would work with php. The images these types of websites have (below) do you believe the images are stored in a mysql database and called like everything else or are they stored differently? If so, how are they called?

http://www.lotpro.com/cars/new/porsche/boxster/
http://www.lotpro.com/search/vehicleinf ... 16/yy0115/

Thanks Everyone!
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Images/PHP and MySql? How does it work?

Post by social_experiment »

It's preferable to not store files in a database;
mcc_shane wrote:The images these types of websites have (below) do you believe the images are stored in a mysql database and called like everything else or are they stored differently? If so, how are they called?
Images could be stored inside the root (or outside) folder and then accessed "normally" like giving a value to an <img > tag.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Images/PHP and MySql? How does it work?

Post by califdon »

Just to elaborate on social_experiment's reply, it's impossible to tell how something is stored if the html is created with php code, since all you can see in the source code is the html that was generated by php. That's the real point: it makes no difference to the browser where the image is located, since it's the web server that has to retrieve it and incorporate it into the data sent to the browser. The reason for recommending storing just the path to the image in the database is based on database performance. It probably doesn't make much difference if it's only a few images and if you don't expect to hardly ever change the images (requiring database maintenance), but storing images directly in a database would introduce complexities in maintaining the database later on if images had to be added, deleted or changed, and perhaps cause performance issues if there were many thousands of images. So it's just a good habit to form, to store the images separately and store the paths to them in the database.
Post Reply