For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > March 2006 > Problem in fetching images from MS Access









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Problem in fetching images from MS Access
G.Insinga

2006-03-15, 6:56 pm

My problem is illustrated in the following PHP code. (I tried to
compromise code minimization and clarity; sorry that file is still
somewhat long);

Any idea?

Thanks in advance to everybody.

G.Insinga

PS. I kindly ask who wants to help, to post answers also to my
private e-mail; for the address, suppress only capitalized
'SPAM'.

<?php
// PHP Version 5.1.2:
//
// This - regardless of the ODBC_BINMODE selected (see below)
// - creates only a ONE BYTE file (while I would like to store
// a whole image, fetched from MS Access).
// Moreover: all (?) the image data are echoed in my web page
// as a meaningless stream of characters (I am testing this
// file ('ImageFromAccess.php') whith a local apache server
// on my Windows XP Home edition system with SP1:
// "http://localhost/ImageFromAccess.php").
//
//
printf("<h3>TRYING TO READ IMAGE DATA FROM ACCESS v.1</H3>");
//
// Connect to the DataBase
$CS = "Driver={Microsoft Access Driver (*.mdb)}; ";
$CS .= "DBQ=C:\\Programmi\\Microsoft Office\\Office\\";
$CS .= "Samples\\NorthWind.mdb;";
$user = "";
$password = "";
$DataBase = odbc_connect($CS,$user,$password)
or die("CAN'T CONNECT TO DATABASE");

// Set handling mode for binary columns
// ('0' -> setting applies by default to new results)
// $BModeS = 'ODBC_BINMODE_PASSTHRU';
$BModeS = 'ODBC_BINMODE_RETURN';
// $BModeS = 'ODBC_BINMODE_CONVERT';
eval("\$BMode = $BModeS;");
printf("<h4>Setting $BModeS (=$BMode)</h4>");
odbc_binmode(0,$BMode) or die("CAN'T SET BINMODE");

// Get table (Table name can vary depending on localisation)
$Query = "SELECT * FROM Categorie";
$QueryRes = odbc_exec($DataBase, $Query)
or die("QUERY FAILED");

// Get one row of the table
// (row numbers seems not to be supported by this driver/DBMS)
odbc_fetch_row($QueryRes) or die("CAN'T FETCH ROW");

// Set handling of long columns ('0' means entire length?)
odbc_longreadlen($QueryRes,0)
or die("CAN'T SET HANDLING MODE OF LONG COLUMNS");

// Get data from 4th column, which contains an image
$ImageData = odbc_result($QueryRes,4)
or die("CAN'T GET 4th COLUMN CONTENTS (MAY BE EMPTY)");

// Put data into a file
$FName = "C:\\Programmi\\Apache Group\\Apache2";
$FName .= "\\htdocs\\myfile.bin";
$Bytes = file_put_contents($FName,$ImageData);
printf("<br><br>$Bytes byte(s) written into the file");

// Close connection
odbc_close($DataBase);
?>
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com