User's Manual
Using Oracle LOBs to Store and Load Employee Images
7-4 Oracle Database Express Edition 2 Day Plus PHP Developer Guide Beta Draft
WHERE employee_id = :eid';
$stid = oci_parse($conn, $query);
$r = oci_bind_by_name($stid, ":eid", $empid, -1);
if (!$r) {
return;
}
$r = oci_execute($stid, OCI_DEFAULT);
if (!$r) {
return;
}
$arr = oci_fetch_row($stid);
if (!$arr) {
return; // photo not found
}
$result = $arr[0]->load();
// If any text (or whitespace!) is printed before this header is sent,
// the text won't be displayed. The image also won't display properly.
// Comment out the "header" line to see the text and debug.
header("Content-type: image/JPEG");
echo $result;
}
?>
The construct_image() function uses the OCI-Lob->load() function to
retrieve the Oracle LOB data, which is the image data. The PHP header()
function sets the MIME type in the HTTP response header to ensure the browser
interprets the data as a JPEG image.
11. Edit anyco_db.inc. Add a new function db_insert_thumbnail() to insert
an image into the EMPLOYEE_PHOTOS table:
function db_insert_thumbnail($conn, $empid, $imgfile, &$e)
{
$lob = oci_new_descriptor($conn, OCI_D_LOB);
if (!$lob) {
$e = db_error($conn, __FILE__, __LINE__);
return false;
}
$insstmt =
'INSERT INTO employee_photos (employee_id, employee_thumbnail)
VALUES(:eid, empty_blob())
RETURNING employee_thumbnail into :etn';
$stmt = oci_parse($conn, $insstmt);
$r = oci_bind_by_name($stmt, ':etn', $lob, -1, OCI_B_BLOB);
if (!$r) {
$e = db_error($stid, __FILE__, __LINE__);
return false;
}
$r = oci_bind_by_name($stmt, ':eid', $empid, -1);
if (!$r) {
$e = db_error($stid, __FILE__, __LINE__);
return false;
}
$r = oci_execute($stmt, OCI_DEFAULT);