|
Posted by ssp on 09/28/05 14:21
Dear all,
finally I found a solution (or better our sysadmin told me to read
mysql manual user comments in detail;):
the trick is: mysql trades BLOBs as kind of huge strings. so one can
use LENGTH on a column to get its content-length and then read out
using SUBSTRING sequentially.
snippet (assuming that $__DB = PEAR:DB Connection is correctly
initiated) :
<?
$stQuery = "SELECT LENGTH(PIF_FILE_BLOB) FROM PIF WHERE PIF_ID=2";
$iFileSize = $__DB->getOne($stQuery);
$i=0;
$iPos = 1; //Startposition
$iLength = 4096; //Readbuffer size
$iTotal = ($iFileSize/$iLength); //how many queries ?
$iStatus = ceil($iTotal/20); //after 20 queries print out a char
//open Output File Handle
printf("Lade neu.exe [%d kB] [",ceil($iFileSize/1024));
$oFileHandle = fopen('.dev/neu.exe','w');
while (!isset($stRead) || $stRead!='') {
$i++;
$stQuery = sprintf("SELECT substring(PIF_FILE_BLOB,%d,%d) FROM PIF
WHERE PIF_ID=2",$iPos,$iLength);
$iPos+=$iLength;
$stRead = $__DB->getOne($stQuery);
fwrite($oFileHandle,$stRead);
if ($i%$iStatus==0) echo "=";
}
echo "]";
fclose($oFileHandle);
?>
This works very good for me
Soeren Sproessig
Navigation:
[Reply to this message]
|