1

I have done some googling and have failed miserably to find an answer to this...

Is it possible stream read/write some binary data from the local FS into a MySQL blob field using Zend Framework's Table/Row gateway classes?

Use Case (slightly contrived I know):

I have on my local FS a 100MB file and wish to store this in a DB (eeekk!). At the moment I'm forced to read this entire file into PHP's memory and then assign it to a Zend_Db_Table_Row_Abstract object before I can save the record to mysql. Is there anyway to assign the a stream to the row object so when I can save the row it just streams from the FS thus massively reducing memory consumption? (and I'd like to the opposite for reading from the DB)

Note: DB server and PHP server run on separate hardware/instances..

Apologies if I have missed some easy way to this or I am asking the impossible, it's just I seem to remember doing this with PostgreSQL and ZF easily enough.

2
  • For reading from file I think you are looking for the LOAD_FILE() MySQL function. For writing to file there is SELECT ... INTO OUTFILE although I am not sure how this works in terms of reproducing the exact file as I have never used it. Commented Jan 31, 2012 at 10:33
  • @DaveRandom Ideally I want to use Zend's classes (or extend them if needs be). Also in my general case the instance running the PHP (and with the file on) is not the same instance as the MySQL server. That said, have never come across 'LOAD_FILE' before, thanks for that Commented Jan 31, 2012 at 10:44

1 Answer 1

2

Theoretical streaming should be possible as described in Large Objects (LOBs). In practise this is only true for writing. There's for more than 8 years an unresolved bug regarding reading streams. You'll have to chose another technology apart from PHP if you want to read streams.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.