I want to know how to store images and files in a MySQL Database.
I want to get images and files like that www.example/rsrc.php/example-image.jpg
example on Facebook: facebook-example.com/rsrc.php/v2/yw/r/svhh826BLKd.png
A Binary Large Object ( BLOB ) is a MySQL data type that can store binary data such as images, multimedia, and PDF files.
Yes, you can store images in the database, but it's not advisable in my opinion, and it's not general practice. A general practice is to store images in directories on the file system and store references to the images in the database.
To insert images into a database, the database must support images. Images are stored in binary in a table cell. The data type for the cell is a binary large object (BLOB), which is a new SQL type in SQL3 for storing binary data.
MySQL databases are sequentially stored on a disk. This means that your database picture files are converted to blobs, embedded into a database, and then kept on a disk.
Create a BLOB column in database table,
probably mediumblob.
but it is good to keep the photo in directory and keep the path in the database. Cheers
CREATE TABLE tblname(ID INT,IMAGE BLOB);
INSERT INTO tblname(ID,IMAGE) VALUES(1,LOAD_FILE('C:/test.txt'));
added the answer from the comments to this question in the answer box..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With