Page 1 of 1
how to insert, update and select blob field
Posted: Wed Nov 09, 2005 9:06 pm
by piseypeng
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
Posted: Wed Nov 09, 2005 10:18 pm
by feyd
it's just like working with any other field type..
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..