Solved

PHP + MySQL - problem with BLOB

Posted on 2002-07-18
9
957 Views
Last Modified: 2008-01-09
Hi,

scripts use MySQL BLOB column to store binary files. I\m speaking about script download.php which should return stored data.

It worked for a long time without any problem. Code is below.

$sql = "SELECT file,filename FROM orders WHERE id = $id";
$result = mysql_query($sql);

$filename = mysql_result($result,0,'filename');
$file = mysql_result($result,0,'file');

Last week we've got a problem. Now variable $file doesn't contains entire BLOB, but only first 8 bytes. I've tried to use  mysql_fetch_row - the same result.

Have anyone seen this before?
0
Comment
Question by:andreif
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7162042
Has the data been truncated on the way into the database?

Instead of returning the data, can you try getting the length of the field in the SQL statement instead?

There is a LENGTH() function on MySQL, so ...

SELECT LENGTH(file),filename FROM orders WHERE id = $id

should at least tell you if the data is OK.

0
 
LVL 6

Author Comment

by:andreif
ID: 7162086
When I use MySQL fron I can see stored data.
Sometimes...

select * from orders where id=1
select id,file from orders where id=1
return complete blob

select file from orders where id=1
returns truncated

All of them returns 8 chars when called from PHP
I repeat, this works last week :(
Thisat script works on another server as well. I suggest, that this is the question of server configuration (may be load)?
0
 
LVL 6

Author Comment

by:andreif
ID: 7162091
length(file) returns 32256 - so it should be okay
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Accepted Solution

by:
Hamlet081299 earned 200 total points
ID: 7163564
Sounds weird.

It looks like you only want one blob column from one row, so a possible workaround is to ...
  select file from orders where id=1 INTO DUMPFILE "/tmp/file.ext"

... and then read then file.

What type of data is it?  Text, image,...?
0
 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7163568
(typo)
... and then read the file.
0
 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7163571
What version of MySQL are you using?  Perhaps an upgrade might make the problem go away.
0
 
LVL 6

Author Comment

by:andreif
ID: 7164319
Data type is binary - it can be .doc, .pdf or something else.
MySQL version is 3.23.49

I'll try DUMPFILE, but anyway, the problem is very interesting I wonder what can be the reason of this strange behaviour.
0
 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7164339
What are the differences between the server that it works on and the one where it doesn't?

Is it the same version of MySQL?

Are they on the same O/S, version?

Are they the same Web Server, version?

Is it the same version of PHP?

0
 
LVL 6

Author Comment

by:andreif
ID: 7168754
OS, MySQL & PHP versions are different, but unfortunately, I can't change this.

Most interesting is the fact that script worked before and administrator says that he haven't changed anything in server configuration last days.

I've spent some time looking for answer in manuals & forums and should say that found nothing. I've seen some mentions about buffer size, but as I see, in my case buffer is big enough.

Anyway, that solution with dumpfile works and thanks to Hamlet for quick & working idea!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question