Solved

PHP + MySQL - problem with BLOB

Posted on 2002-07-18
9
954 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
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

830 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