PHP/MySQL Conundrum: Inserting Large Data with PHP Memory Limits
I recently inherited a PHP application that stores uploaded PDF and JPG files in a MySQL database. Unfortunately, it is way beyond scope (and original architecture) to change this fact. Given that, there are some memory limit problems when the initial file is quite large as it’s contents are read to a variable which is evetually placed into the MySQL INSERT query.
Is there a method of updating/inserting to a MySQL field with binary/data directly from disk, or of somehow not reading in the file contents through PHP?
Also, my first thought was to buffer the file in with PHP and use CONCAT, where PHP only has a portion of the data at any given time – but that would require many DB queries (one for each buffered portion of the file), not to mention the very idea just sounds wrong.
Am I thinking about this the wrong way?
UPDATE:
There is a way, and it’s documented in the MySQL Manual, tho’ it took me a bit of searching to find it. The problem, in my case, is that it comes with this caveat:
To use this function, the file must be located on the server host, you must specify the full pathname to the file, and you must have the
FILEprivilege.
Which makes sense, but will probably prevent me from being able to use this method.

Sorry, Comments are Closed.