【发布时间】:2016-04-18 13:54:40
【问题描述】:
图像已存储在数据库中。我制作了一个 php 页面,以便查看存储在我的 ms sql 数据库中的所有数据。它只显示图像的文件名而不是实际图像
<?php
$serverName = "kwekwe\SQLEXPRESS";
$connectionInfo = array( "Database"=>"customerdb", "UID"=>"dbadmin", "PWD"=>"kwe[enter image description here][1]" );
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
//declare the SQL statement that will query the database
$query = "SELECT * FROM Customer_Details";
//execute the SQL query and return records
$result = sqlsrv_query($conn, $query)
or die( print_r( sqlsrv_errors(), true));
//Show results in table
$o = '<table border=1 id="myTable">
<thead>
<tr>
<th>Customer ID</th>
<th>Customer Name</th>
<th>Image</th>
</tr>
</thead><tbody>';
while ( $record = sqlsrv_fetch_array($result) )
{
$o .= '<tr><td>'.$record ['Cust_ID'].'</td>';
$o .='<td>'.$record ['Cust_Name'].'</td>';
$o .='<td><img height=127 width=127 src=data:image;base64>'.$record ['image'].'</td>';
$o .='</tr>';
}
$o .= '</tbody></table>';
echo $o;
//free result set memory
//mssql_free_result($result);
//close the connection
//sqlsrv_close($dbhandle);
?>
【问题讨论】:
-
图片是
BLOB的类型吗?还是只是图片的路径? -
如果我没弄错的话,你可以在 img 标签的 src 属性中回显文件名,而不是像
<td>元素一样显示:$o .='<td><img height=127 width=127 src="'.$record ['image'].'"></td>';
标签: php sql-server database html