Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP batch extract DB row BLOBs to files
    primarykey
    data
    text
    <p>We are in the midst of a data migration , and the project needs from one particular table BLOB data saved to files, and sent to the vendor, due to their structure</p> <p>I am able to achieve this one at a time, but needed to create a batch process, as there are 50,000 rows/potential files.</p> <p>my current code is </p> <pre><code> $sql = "SELECT a.guid AS file_name, a.attachment AS file_blob" ." FROM attachment a"; $squery = oci_parse($link, $sql); oci_execute($squery); while ($row = oci_fetch_array($squery, OCI_ASSOC | OCI_RETURN_LOBS)) { header('Content-type: octet-stream;'); header('Content-disposition: attachment;filename='.$row['FILE_NAME']); print $row['FILE_BLOB']; } oci_free_statement($squery); </code></pre> <p>I do understand that I would rather be saving the data rather than streaming it to the browser, I just am not wrapping my head around how to achieve this, should i be looking at php file I/O fputs()?</p> <p>End result is I would like the process to batch write binary files based on the query to a folder </p> <p><strong>EDIT</strong></p> <p>Thank you for your direction and help, based on that I ended up coming up with two separate ways to achieve this first i did the following getcwd() to verify where the server was pointing to, and did an absolute path if needed</p> <pre><code> $basedir = '/path/to/host/www/blobdoc/'; </code></pre> <p>set permissions on the blobdoc folder then used either of the following scripts in the while loop</p> <pre><code> $filename=''; $filename=$basedir.$row['FILE_NAME']; file_put_contents( $filename, $row['FILE_BLOB']); </code></pre> <p><br/></p> <pre><code> $filename=''; $filename=$basedir.$row['FILE_NAME']; $File = @fopen( $filename, 'w' ); if( $File ) { if( FALSE === fwrite( $File, $row['FILE_BLOB'] )) return FALSE; fclose( $File ); return TRUE; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload