显示来自MySQL的blob PNG图像

时间:2013-06-13 14:48:34

标签: php mysql blob

我正在使用jquery mobile构建一个webapp,我一直试图从MySQL DB中显示一个BLOB PNG图像,但没有成功。我想知道我做错了什么。

这是我的popup_data.php

<?php
$con = mysqli_connect('127.0.0.1','root' , '' , 'parkinglot');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$index_data = 1;
$tables = "show tables";
$result = mysqli_query($con,$tables);

while($row = mysqli_fetch_array($result,MYSQLI_NUM))
{    
    echo '
    <div data-role="popup" id="mapdata'.$index_data.'" class="ui-content" data-theme="a"> ';

    echo '<img src="showimage.php?sensor_num='.$index_data.'" />'; //sensor_num is to retrieve the image with that ID

    echo '    
    </div>
    ';
$index_data++;
};
?>

这是我的showimage.php

<?php
$con = mysqli_connect('127.0.0.1','root' , '' , 'parkinglot');

// CHECK CONNECTION
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sensor_num = (isset($_GET['sensor_num']) && is_numeric($_GET['sensor_num'])) ? intval($_GET['sensor_num']) : 0;

$data = "SELECT * FROM $table_name2 WHERE sensor_num=$sensor_num";
$result2 = mysqli_query($con,$data);

while ($row2 = mysqli_fetch_array($result2))
{
   $imgData = $row2['picture'];
}
header('Content-Type: image/png');
echo $imgData;
?>

1 个答案:

答案 0 :(得分:0)

$data = "SELECT * FROM $table_name2 WHERE sensor_num=$sensor_num";

您没有在showimage.php内的任何位置设置$table_name2