我正在尝试将一张图片存储到数据库中,但出现了问题。这是我的表结构:
mysql> describe ImageStore;
+---------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+
| ImageId | int(11) | NO | PRI | NULL | |
| Image | longblob | NO | | NULL | |
+---------+----------+------+-----+---------+-------+
2 rows in set (0.01 sec)
这是我的查询,它应该插入图片,或者至少我希望如此:
//Store the binary image into the database
$tmp_img = $this->image['tmp_name'];
$sql = "INSERT INTO ImageStore(ImageId,Image)
VALUES('$this->image_id','file_get_contents($tmp_image)')";
mysql_query($sql);
如果我打印 file_get_contents($tmp_image) 的值,那么屏幕上会显示大量数据。但是这个值没有被存储在数据库中,这就是我面临的问题。