PHPBuddy.com
 PHP Function Lookup:
 
Categories
PHP Quick Start
PHP Installation
PHP Articles
PHP Scripts

Top Rated Articles 
  • Simple Ad Rotator
  • PHP and Cookies
  • Getting Screen resolution using JavaScripts & PHP
  • Using Functions in PHP
  • PHP Sessions

  • Site Related
    Submit Articles/Code
    Contact Us
    Home

       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.phpView 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.phpView Sample Output


    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 - 2017 PHPbuddy.com Unauthorized reproduction/replication of any part of this site is prohibited.