使用 php 在 MySql 数据库中插入 Blob
我试图在数据库中存储图像,由于某种原因它似乎不起作用。这是我的表的结构。
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)的值,那么屏幕上有大量的数据。但是这个值不会存储在数据库中,这就是我面临的问题。