我尝试从Oracle 10g数据库加载blob图像。我在.ASP VB和.PHP中都试过了。
TABLE = STD_IMAGE
Name Null? Type
------------------------------- -------- ----
IMG_ID_NO NOT NULL NUMBER(10)
IMG_IMAGE NOT NULL BLOB
ASP代码
<%@ LANGUAGE="VBSCRIPT" %>
<%Option Explicit
Dim Rs, sSQL, OBJdbConnection
' Clear out the existing HTTP header information
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear
'Change the HTTP header to reflect that an image is being passed.
Response.ContentType = "image/jpg"
Set OBJdbConnection = Server.CreateObject("ADODB.Connection")
OBJdbConnection.Open "Provider=OraOLEDB.Oracle;Data Source=xxxxxx;User Id=xxxx;Password=xxxxx;"
DIM itemID
itemID = request.querystring("InventoryItemId")
itemID = 25
sSQL = "Select * from std_image where IMG_ID_NO=25"
set rs = OBJdbConnection.Execute(sSql)
If not rs.eof Then
Response.BinaryWrite rs("IMG_IMAGE")
Response.End
End If
CloseRecordset(rs)%>
<%Set OBJDbConnection = nothing%>
PHP代码
<?php
$db ="(DESCRIPTION =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = xxxxxx)
(PORT = 1522)
)
(CONNECT_DATA = (SID = xxxxx))
)";
$odbc = ocilogon ('xxxxxx', 'xxxxxx', $db) or die( "Could not connect to Oracle database!") or die (ocierror());
$sql = "SELECT IMG_IMAGE FROM std_image WHERE IMG_ID_NO = 25";
$stid = ociparse($odbc, $sql);
ociexecute($stid);
$row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS);
if (!$row) {
header('Status: 404 Not Found');
} else {
$img = $row['IMG_IMAGE']->load();
header("Content-type: image/jpg");
print $img;
}
?>
对于这两个示例,我都会收到以下消息:
The image “http://localhost/test_ShowImage.asp” cannot be displayed because it contains errors.
The image “http://localhost/test_getImage.php” cannot be displayed because it contains errors.
答案 0 :(得分:0)
我用你的代码作为我的基础,它起作用了。我虽然使用了PHP ADODB库。
include("settings.php"); //includes db connection
$docid = $_REQUEST['document_id'];
$sql = "SELECT DOCUMENT_FILE FROM ACCOUNTS_DOCUMENTS WHERE DOCUMENT_ID = ".$docid;
$rs = $db->Execute($sql);
header("Content-type: image/jpg");
print $rs->fields['DOCUMENT_FILE'];