Rabu, 04 Februari 2009

MySQL and BLOBs - Sending Data Into the BLOB Column




Let's start by loading an image into the database. In addition to our connection object, we will need a RecordSet object and a Stream object. Let's begin by declaring these two objects.

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

An ADO Stream object can handle both text and binary data (and can therefore be used to get large text fields as well as BLOB fields). We have to specify which type of data we will be dealing with using the adTypeBinary value in the Type parameter.

The first thing we need to do is open a blank recordset and add a new record to it.

rs.Open "SELECT * FROM files WHERE 1=0", conn, adOpenStatic, adLockOptimistic
rs.AddNew

We now have an empty recordset (thanks to the WHERE clause) to work with, to which we have added a new row. Next we load a file to add to this recordset using the stream object.

mystream.Open
mystream.LoadFromFile "c:myimage.gif"

Once we have a file loaded into the stream, we can populate the recordset and update it back to MySQL:

rs!file_name = "myimage.gif"
rs!file_size = mystream.size
rs!file = mystream.read
rs.Update
mystream.Close
rs.Close
conn.Close

We have assigned the details of the file into the recordset, then proceeded to "read" the data out of the stream and into the file field of the recordset. Running a select statement on your MySQL server should show the row to now be present in your database. It is important to note that data will only pass to the server during the update statement of the recordset object; the stream object methods do not cause data transfers to and from the server.


source :http://www.devarticles.com


--------------------------------------------------


Trik Membuat-halman next

Trik membuat-security-code

Trik mengecek-karakter

Trik merubah-pswd root

Trik Noise-dimouse

Trik penerapan BUG

Trik penggabungan-2web

Trik perkenalan-dengan-php

Trik PHP-Login-script