Export pictures from MySQL database...

ullenulle
ullenulle used Ask the Experts™
on
Hi there.

I have some Pictures stored in a MySQL database. Yeah yeah... I know it's not the best solution, but I didn't have a safe option to put them on a fileserver. Anyway... What is the best way to export the Pictures? I usually use phpMyAdmin to Work with my databases, but I also use MySQL Workbench 6.2 once in a while.
Any suggestion how to export all Pictures in one step or alternatively a few steps? The variables in the table is like this:
Picture_id (int(11) primary key, auto increment)
Picture1 (longblob)
Picture_filename (varchar(50)
Picture_date (date)
Picture_filesize (int(11)
Picture_description (varchar(1000))

Best regards

Ulrich
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mukesh YadavFull Stack Developer

Commented:
Where you want to export pictures?
Kamal KhaleefaInformation Security Specialist

Commented:
you can use this code to connect to ur data base and export all images
Private Sub lpSaveDocuments()

        Dim dsDocuments As DataSet
        Dim dsDoc As DataSet
        Dim intRowCnt As Integer

        Dim strSql As String = ""
        Dim strsqlDoc As String = ""

        Dim strFileName As String = ""
        Dim strDirPath As String = ""
        Dim strFilePath As String = ""

        strSql = <Outer SQL if needed>

        dsDocuments = GetMyimagesFromDB()
'GetMyimagesFromDB is a function that returns a dataset of images,image name ...etc
        Try

            If Not (dsDocuments Is Nothing OrElse dsDocuments.Tables.Count = 0 OrElse dsDocuments.Tables(0).Rows.Count < 1) Then

                'Open & Save Doc
                For intRowCnt = 0 To dsDocuments.Tables(0).Rows.Count - 1

                    strFileName = <File Name, It could be from database if present>

                    strFilePath = ""

                    Dim arrByteData() As Byte

                    strDirPath = <Path to the Directory where extracted file is to be saved>

                    strsqlDoc = <SQL for selecting the binary field>

                    dsDoc =  <Open the dataset>

                    If Not (dsDoc Is Nothing OrElse dsDoc.Tables.Count = 0 OrElse _
                        dsDoc.Tables(0).Rows.Count < 1) Then

                        arrByteData = dsDoc.Tables(0).Rows(0)("<Binary field name>")

                        strFilePath = String.Concat(strDirPath, strFileName)

                        Dim fs As System.IO.FileStream = _
                                New System.IO.FileStream(strFilePath, IO.FileMode.CreateNew, IO.FileAccess.ReadWrite)

                        Dim bw As System.IO.BinaryWriter = New System.IO.BinaryWriter(fs)

                        bw.Write(arrByteData)
                        bw.Flush()
                        bw.Close()

                        fs.Close()
                        fs.Dispose()

                    End If

                    If Not (dsDoc Is Nothing) Then
                        dsDoc.Dispose()
                    End If
                Next
            End If

            If Not (dsDocuments Is Nothing) Then
                dsDocuments.Dispose()
            End If

        Catch ex As Exception


        End Try

    End Sub

Open in new window

Author

Commented:
Hi Again.

I want to save the Pictures to a drive, MS SharePoint etc..

king2002: Forgive me if my question is stupid, but is that code VB, asp or aspx?
And what does this one mean: strSql = <Outer SQL if needed>

Best regards

Ulrich
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Kamal KhaleefaInformation Security Specialist

Commented:
this is VB.Net

<Outer SQL if needed> this mean you can put here another sql if needed to get ur data

you can ignore it if you don't needed

Author

Commented:
Hi king2002.

Thank you for your info. Forgive me if I'm a bit slow. Where do I put my connectionstring? And all the:

Dim xxxxxx As String = ""

Shall I add something in the "" ??

Best regards

Ulrich
Kamal KhaleefaInformation Security Specialist

Commented:
Hi

put your connection string inside this function

GetMyimagesFromDB()

where you will write your sql to get the images from DB

Author

Commented:
Hi King2002.

Thank you for your reponse. Must I trigger the funktion with a button, or will it launch at page load?
And what about the other ""  in your code snippet (all the Dim as Sting .... = "")? Are they supposed to be empty?

Best regards

Ulrich

Author

Commented:
I'm working on the issue these days and will close the question myself and reward points!

Author

Commented:
Ops... missed the object button. :-)
Hey everyone.

My apology for no response. I had to use a quick solution and use a software to extract the pictures from the MySQL database. The software is MyLobEditor and worked very fine.
I will award the points to King2002 for his efford, and I'm sure it would work. I just didn't have time to test it for real. Sorry. But thank you King2002. :-)

Best regards

Ulrich

Author

Commented:
Thank you.

Author

Commented:
Case closed.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial