473,230 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

Reading Database BLOB with showing progress information

ssp
Dear all,

I'm dealing with a very tricky problem and can't seem to find the
answer with google. the problem is: i want to store huge data
(binaries) inside a mysql databases blob - to later store those data to
a file somewhere else (from where i can connect the database).

problem comes into play, when I try to output a "progress" of the
reading of this data (kind of "xx bytes of XXX bytes already
transmitted").

Does PHP / PDO /PEAR:DB has those Buffered Read capabilities for Table
Columns ?

Has anybody done this before ?

Many thanks in advance....
Soeren

Sep 27 '05 #1
5 2033
In article <11**********************@f14g2000cwb.googlegroups .com>,
"ssp" <ss*@planicsware.de> wrote:
Dear all,

I'm dealing with a very tricky problem and can't seem to find the
answer with google. the problem is: i want to store huge data
(binaries) inside a mysql databases blob - to later store those data to
a file somewhere else (from where i can connect the database).

problem comes into play, when I try to output a "progress" of the
reading of this data (kind of "xx bytes of XXX bytes already
transmitted").

Does PHP / PDO /PEAR:DB has those Buffered Read capabilities for Table
Columns ?

Has anybody done this before ?

Many thanks in advance....
Soeren


Don't think you'll be able to do this, AFAIK. Leastways, if you do, it
won't be with php, which is strictly server-side.

With php, the best I think you can do is report the total bytes to of
the object to be transfered in the headers and the browser will report
file transfer progress if it's supports that. IE and Safari do this.
But having php talk to the browser and continuously report back periodic
progress isn't possible.

You might start looking into writing a java-based client-server pair
that can do the handshaking, file transfer, and report on progress.

--
DeeDee, don't press that button! DeeDee! NO! Dee...

Sep 27 '05 #2
ssp
thanks for your answer.

the problem is: i'm writing a kind of multiplatform php-cli application
and do not have a browser - so reporting the transfered bytes is a very
handy feature...do you have any other ideas?

many thanks

Sep 28 '05 #3
ssp
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

Sep 28 '05 #4
On 28 Sep 2005 01:30:28 -0700, "ssp" <ss*@planicsware.de> wrote:
thanks for your answer.

the problem is: i'm writing a kind of multiplatform php-cli application
and do not have a browser - so reporting the transfered bytes is a very
handy feature...do you have any other ideas?


Incorporate a browser.
--
gburnore@databasix dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
DataBasix | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ۳
Black Helicopter Repair Svcs Division | Official Proof of Purchase
================================================== =========================
Want one? GET one! http://signup.databasix.com
================================================== =========================
Sep 28 '05 #5
On 28 Sep 2005 04:21:07 -0700, "ssp" <ss*@planicsware.de> wrote:
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


I've seen this sort of thing before. Adding some time to the actual
process to show progress makes the user believe it's going "faster"
than if they see nothing happening.
--
gburnore@databasix dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
DataBasix | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ۳
Black Helicopter Repair Svcs Division | Official Proof of Purchase
================================================== =========================
Want one? GET one! http://signup.databasix.com
================================================== =========================
Sep 28 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: John | last post by:
I have over 5000 thumbnail pictures of size 5kb each. I would like to able to load all 5000 pictures and view 50 per page using mysql_data_seek(). I would like to know what are the advantages and...
2
by: Dariusz | last post by:
Below is part of a code I have for a database. While the database table is created correctly (if it doesn't exist), and data is input correctly into the database when executed, I have a problem...
2
by: Plex | last post by:
Ok, I've written this script which is supposed to take an image uploaded by a user and put it in to a database, then at a later date be able to extract the image from the database and display the...
3
by: Johan Vervoort | last post by:
How can I read a binary value from a blob via ODBC (Microsoft VFP driver-win32all)? The value seems to be truncated at the first '\0' TIA
5
by: Ken | last post by:
Hello, I'm trying to read a Blob from Oracle and then write it to an audio file(.AU). I'm using Visual Studio.Net 2003 (VB). I can't seem to get my code to work. Will someone take a look at it...
1
by: Roberto Castro | last post by:
I have some problems with the way I am showing the BLOB fields in the Image web controls. It does work on my localhost though sometimes I need to hit Refresh for the images to load properly....
2
by: Chucker | last post by:
Hi Community, I think I can store Binary Data in SQL Server but when I try to retrieve it, I always only get one byte. I think I stored my Binary Data in SQL Server in a Colum of Type Image....
4
by: Kevin Mansel via .NET 247 | last post by:
Ok, basically this is my problem. I'm building a console app tocall a dos program. So i'm using the Shell command to call theprogram, now depending on what happens, I want to read theoutput that...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.