Hello All,
I just start using PHP and MYSQL and I don't know how to Insert, update and select data from blob field.
Can somebody give me a sample code of how to insert a picture to blob field and code to select it back.
I am appreciate your help. Thanks.
Pisey
how to insert, update and select blob field
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
it's just like working with any other field type..
However, it is highly recommended to not store images in a database. Main reasons: to display an image, you must have a script be able to pull a single image from the database and return the binary data. A page will reference this script via an image tag. This operation increases server overhead needlessly (most often). As an example, if you want to show multiple images on a page, each image will have to reference this image script to request a single image, each one will require the database server to unpack the binary data, transfer it to php, then php outputs it to the web server's buffers..
Code: Select all
$filedata = file_get_contents('filename.jpg');
mysql_query('INSERT INTO `table` (`field`) VALUES(\'' . mysql_real_escape_string($filedata) . '\')');
// ...
$query = mysql_query('SELECT `field` FROM `table`');However, it is highly recommended to not store images in a database. Main reasons: to display an image, you must have a script be able to pull a single image from the database and return the binary data. A page will reference this script via an image tag. This operation increases server overhead needlessly (most often). As an example, if you want to show multiple images on a page, each image will have to reference this image script to request a single image, each one will require the database server to unpack the binary data, transfer it to php, then php outputs it to the web server's buffers..