MySQL
  Home arrow MySQL arrow Page 2 - Blobbing Data With PHP and MySQL
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Blobbing Data With PHP and MySQL
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 252
    2002-02-05

    Table of Contents:
  • Blobbing Data With PHP and MySQL
  • Creating the database
  • Adding blobs to the database
  • The grabfile.php script
  • Displaying the files
  • The downloadfile.php script
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Blobbing Data With PHP and MySQL - Creating the database


    (Page 2 of 7 )

    Our document repository will use one database containing one table to store its data. Using the MySQL console application (c:\mysql\bin\mysql.exe for Win32 or /usr/bin/mysql for *nix users), create our database and switch to it with the following commands:

    create database myFiles;

    use myFiles;


    Now let's create the table that will actually store our BLOB's as part of our myFiles database:

    create table myBlobs

    (

    blobId int auto_increment not null,

    blobTitle varchar(50),

    blobData longblob,

    blobType varchar(50),

    primary key(blobId),

    unique id(blobId)

    );


    We now have one database named myFiles, which contains one table named myBlobs. The details of each field in the myBlobs table are shown below:
    • blobId: An integer that will provide us with a unique numerical identifier for each blob (ie 1, 2, 3, etc). It is incremented and tracked internally by MySQL whenever we add a new record.
    • blobTitle: A description of each blob in the table, for example "My word document about golf", or "Picture of the sky". Servers no real purpose, but will come in handy when we are viewing our files in through a web page later on.
    • blobData: A binary field that will hold the contents of each file that we wish to store in the database. In our table, we have used the longblob data type, which can hold up to 4,294,967,295 characters. Other binary field types include mediumblob (which can hold up to 16,777,215 bytes), blob (which can hold up to 65535 characters), and tinyblob (which can hold up to 255 characters).
    • blobType: As you will see shortly, each different file type (such as .doc, .gif, .pdf, etc) has its own unique content type. When a file is uploaded via a web browser to a web server (which we will look at shortly), the browser cleverly passes that files type as part of its headers. We will be storing this type in the table so that we can choose to view only specific types of files from our myBlobs table. Content types are simple strings. The content type for a MS word document is "application/msword", the content type for a GIF image is "image/gif", etc.

    More MySQL Articles
    More By Mitchell Harper


     

    MYSQL ARTICLES

    - MySQL and BLOBs
    - Two Lessons in ASP and MySQL
    - Lord Of The Strings Part 2
    - Lord Of The Strings Part 1
    - Importing Data into MySQL with Navicat
    - Building a Sustainable Web Site
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - PhpED 3.2 – More Features Than You Can Poke ...
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - Security and Sessions in PHP
    - Setup Your Personal Reminder System Using PHP
    - Create a IP-Country Database Using PERL and ...
    - Developing a Dynamic Document Search in PHP ...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT