Reply to Solution (was: Re: Reading Database BLOB with showing progress information)

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация