Home arrow MySQL arrow Page 5 - MySQL and BLOBs
MYSQL

MySQL and BLOBs


One of MySQL's strengths is its use of Binary Large Object (BLOB) columns. These columns store unprocessed binary data, typically files, that can be retrieved and manipulated like the other common datatypes. The difficulty comes in accessing the BLOB column in VB. Prior to ADO 2.5, the only way to move data in and out of a MySQL BLOB column using Visual Basic was to use the appendchunk and getchunk methods. With ADO 2.5, the stream object has been added, greatly simplifying the process of working with MySQL BLOBs. In this article, I will focus entirely on using the stream object.

Author Info:
By: Mike Hillyer
Rating: 4 stars4 stars4 stars4 stars4 stars / 99
May 18, 2004
TABLE OF CONTENTS:
  1. · MySQL and BLOBs
  2. · Connection String
  3. · Connection Object
  4. · Sending Data Into the BLOB Column
  5. · Retreiving Data
  6. · Update File - We're Done!

print this article
SEARCH DEVARTICLES

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.


blog comments powered by Disqus
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 ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials