PHP Function Lookup:
PHP Quick Start
PHP Installation
PHP Articles
PHP Scripts

Top Rated Articles 

Site Related
Submit Articles/Code
Contact Us
Instant cash loans, cash advance online same day

   Home                   Article Added on: April 7, 2002
Storing Binary Data in MySQL Databases

Overview: A lot of people are curious to know how to add binary data such a Zip files, images etc in a MySQL Database, this articles shows you how to store binary data in a MySQL database and then how to reterive them back.

Binary data can be stored in a MySQL database in a BLOB field.

"A BLOB is a binary large object that can hold a variable amount of data." This essentially means that BLOB is a datatype that can hold binary content, and we can use it to store files.

In order to understand the concept I will work with an example we will first create a table, then I will show you how to add (Binary Data) in it and then reterive it back.

Creating a Sample Table: We will name the table as 'binary_data_files' which will hold our Binary Data.

CREATE TABLE binary_data_files
(file_id tinyint(3) unsigned NOT NULL auto_increment,
bin_data mediumblob NOT NULL,
description tinytext NOT NULL,
filename varchar(50) NOT NULL,
filesize varchar(50) NOT NULL,
filetype varchar(50) NOT NULL,
PRIMARY KEY (file_id));

Now that we have a table I made a HTML Form, from where we can upload Binary Data (binary_form.htm)

add_binary_data.php View Sample Output

Okay now that we have added data to the database, we will write a programm that shows the data in a table and another programme that retrives it.

We have two programms the first view_data.php and the second download_binary_data.php the first programme view_data.php is a very simple programme that lists the details of the entire table where our data is stored in a neat table.

view_data.php View Sample Output
"; echo ""; //description echo ""; //filesize echo ""; //filetype } ?>
File Name Description File size File type
" . $rs[2] ."". $rs[1] ."". ($rs[3]/1024) ." KB". $rs[4] ."

* Click on the file name to download the file

download_binary_data.php which downloads the actual data.

Rate this article:  Current Rating: 2.07
  Poor    Excellent     
          1     2    3    4    5


Home | Privacy Policy | Contact Us | Terms of Service
(c) 2002 - 2018 www.PHPbuddy.com Unauthorized reproduction/replication of any part of this site is prohibited.