473,395 Members | 1,641 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,395 software developers and data experts.

Read blob over ODBC from db2 to file

10
Hello everyone,

i am trying to extract blob data into a file and then pass it to the user for download...

The code i wrote should work, but as i have tested it so far it crashes my apache server. I am using apache version 2.2.14, php version 5.2, DB2 9.5 fix pack 2. My connection is open over ODBC ( $conn=odbc_connect('SAMPLE','USER','PASS') )

This is the code:
Expand|Select|Wrap|Line Numbers
  1. $sql = "SELECT file, filename FROM file where filename = 'a.txt'";
  2.     $res = odbc_exec($conn, $sql);
  3.     if (!$res)
  4.     {exit("Error in SQL");}
  5.     $filename = './Datoteke/'.$Datoteka;
  6.     $Blob=odbc_result($res, "file");
  7.         $filename=odbc_result($res, "filename");
  8.     if (is_null($Blob))
  9.       {
  10.     ECHO "  NULL LOB indicated.\n";
  11.     }ELSE{
  12.     $fh = fopen($filename, "wb");
  13.     $noc = strlen($Blob);
  14.     for ($i = 0; $i < $noc; $i = $i+2)
  15.     {
  16.         $hchr = substr($Blob, $i, 2);
  17.         $dchr = hexdec($hchr);
  18.         $aschr = chr($dchr);
  19.         fwrite($fh, $aschr);
  20.     }
  21.     fclose($fh);
  22.     }
  23.  
Appache gives me this error:
[Mon Oct 18 10:00:24 2010] [notice] Parent: child process exited with status 3221225477 -- Restarting.
[Mon Oct 18 10:00:24 2010] [notice] Apache/2.2.14 (Win32) PHP/5.2.12 mod_jk/1.2.30 configured -- resuming normal operations
[Mon Oct 18 10:00:24 2010] [notice] Server built: Sep 28 2009 22:41:08
[Mon Oct 18 10:00:24 2010] [notice] Parent: Created child process 8320
[Mon Oct 18 10:00:26 2010] [notice] Child 8320: Child process is running
[Mon Oct 18 10:00:26 2010] [notice] Child 8320: Acquired the start mutex.
[Mon Oct 18 10:00:26 2010] [notice] Child 8320: Starting 64 worker threads.
[Mon Oct 18 10:00:26 2010] [notice] Child 8320: Starting thread to listen on port 80.


I have tryed using this on example X.JPG and it returned half of the picture. The server didnt crash tho. Then i tryed it on a PDF - name used some special characters ( PRP_77_DEJAN_20100409_152103.pdf ) the server crashed. I tryed it on 10 other files and it always crashes.

Any help will be very apriciated.

If you have a better idea on this or how to do this without saving a file to filesistem and just direct transfer to user, that would be even better.

With regards,

Marko

Edited:

I changed the way i transfer files from odbc to PDO odbc since in odbc i just set the vairable to some string variable.

Now i can get a file that is rager then 32K out of the DB but it seems i get an timeout on files larger then 100k ( from what i have tested so far ).

This seems to be an apache issue tho so i will close this down and try to get some help there.
Oct 18 '10 #1
0 2129

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: rohisingh | last post by:
I have a tar file. The content of the file are as following. rohits@sandman 12-08-04 $ tar tvf 20041208.tar drwxr-xr-x root/root 0 2004-12-08 21:39:19 20041208/ -rw-r--r-- root/root ...
5
by: Pete | last post by:
I having a problem reading all characters from a file. What I'm trying to do is open a file with "for now" a 32bit hex value 0x8FB4902F which I want to && with a mask 0xFF000000 then >> right...
4
by: ESPN Lover | last post by:
Below is two snippets of code from MSDN showing how to read a file. Is one way preferred over the other and why? Thanks. using System; using System.IO; class Test { public static void...
8
by: a | last post by:
I have a struct to write to a file struct _structA{ long x; int y; float z; } struct _structA A; //file open write(fd,A,sizeof(_structA)); //file close
5
by: lovecreatesbea... | last post by:
The condition at line 31 is added to check if the program finished to read the whole file. Is it needed and correct? Thank you. #include <fstream> #include <iostream> #include <string> using...
1
by: Neerajpant | last post by:
Hi, I am facing problem while reading blob field from paradox database by using ADO. If anybody knows how to read blob fields from Paradox database by using MS Technologies, then please let me...
6
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to read a file line by line (with std::string line)....
1
by: jamal8t2 | last post by:
i have inserted blob data in database , but i am not able to access back that data to the browser. i have php script but it does not work proprly. our script is below if ($_REQUEST == 1) { ...
9
by: vineeth | last post by:
Hello all, I have come across a weird problem, I need to determine the amount of bytes read from a file, but couldn't figure it out , My program does this : __ file = open("somefile") data =...
4
by: =?ISO-8859-1?Q?Hans_M=FCller?= | last post by:
Good morning folks, I cannot read a binary file into a mysql database. Everything I tried did not succeed. What I tried (found from various google lookups...) is this: con =...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.