Solved

PHP + MySQL - problem with BLOB

Posted on 2002-07-18
9
960 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
Independent Software Vendors: 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

623 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