MySQL
  Home arrow MySQL arrow Page 5 - MySQL and BLOBs
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  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
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

MySQL and BLOBs
By: Mike Hillyer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 67
    2004-05-18

    Table of Contents:
  • MySQL and BLOBs
  • Connection String
  • Connection Object
  • Sending Data Into the BLOB Column
  • Retreiving Data
  • Update File - We're Done!

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    MySQL and BLOBs - Retreiving Data


    (Page 5 of 6 )

    Ok, so now that our image is in the table, we need to get it back out. As we have covered them already, let's get the connection and recordset objects initialized right away:

    Dim conn As New ADODB.Connection
    conn.ConnectionString = GloConnectionString
    conn.CursorLocation = adUseClient
    conn.Open

    Dim rs As New ADODB.Recordset
    Dim mystream As New ADODB.Stream
    mystream.Type = adTypeBinary

    rs.Open "Select * from files WHERE files.file_id = 1", conn

    We have opened a connection and a recordset and also declared our stream. To get our file back out, we open the stream, write to it from the recordset, and then save the data to a file, as follows:

    mystream.Open
    mystream.Write rs!File
    mystream.SaveToFile "c:newimage.gif", adSaveCreateOverWrite

    mystream.close
    rs.Close
    conn.Close

    We load the binary data out of the recordset using the mystream.Write rs!file syntax, where rs!file is the field of the recordset that contains the binary data we will "write" to the stream. The SaveToFile method takes two arguments: the target location, and a variable that determines the stream's actions when a file exists. When adSaveCreateOverWrite is specified, existing files will be overwritten. When adSaveCreateNotExists is specified, files will not be overwritten if they exist.

    More MySQL Articles
    More By Mike Hillyer


       · "mystream.Write rs!file"should be:mystream.Write rs.Fields(0).Value
     

    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 5 hosted by Hostway