Solved

PHP + MySQL - problem with BLOB

Posted on 2002-07-18
9
938 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:RQuadling
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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

707 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now