type - how to store pdf file in mysql database
How to insert a file in MySQL database? (3)
I want to insert a file in MYSQL database residing on a remote webserver using a webservice.
My question is: What type of table column (e.g. varchar, etc.) will store a file? And will the insert statement be somewhat different in case of a file?
File size by MySQL type:
- TINYBLOB 255 bytes = 0.000255 Mb
- BLOB 65535 bytes = 0.0655 Mb
- MEDIUMBLOB 16777215 bytes = 16.78 Mb
- LONGBLOB 4294967295 bytes = 4294.97 Mb = 4.295 Gb
The BLOB datatype is best for storing files.
- See: How to store .pdf files into MySQL as BLOBs using PHP?
- The MySQL BLOB reference manual has some interesting comments
You need to use BLOB, there's TINY, MEDIUM, LONG, and just BLOB, as with other types, choose one according to your size needs.
TINYBLOB 255 BLOB 65535 MEDIUMBLOB 16777215 LONGBLOB 4294967295 (in bytes)
The insert statement would be fairly normal. You need to read the file using
fread and then
addslashes to it.