Insert images in Mysql/Mariadb

Post Reply
User avatar
Marc Venken
Posts: 727
Joined: Tue Jun 14, 2016 7:51 am

Insert images in Mysql/Mariadb

Post by Marc Venken »

Hello,

Looking into the posts, i didn't find my solution for the folowing problem.

All members of my soccer club will give me the pictures of each player to put into a online member system.
I put a field by MyAdmin into the database with folowing data :

Name "foto" and type "MEDIUM BLOB"

I see that I get a upload buttom from Phpmyadmin, and that Xbrowse is showing the picture afther I upload

I Use Xbrowse for all screens, but how do I put the files, that I have on disk into each row of Xbrowse for the online database ?
In a normal dbf structure, I always put a link (c:\foto\image1212) to a file on disk and show it that way, but with SQL/Maria it will go into the BLOB database ?

How do I proceed ?

Maybe the online invoice sample can be expanded with product foto's show into the xbrowse and insert from files on disk ?
Marc Venken
Using: FWH 20.08 with Harbour
nnicanor
Posts: 296
Joined: Fri Apr 23, 2010 4:30 am
Location: Colombia

Re: Insert images in Mysql/Mariadb

Post by nnicanor »

Hi Marc,

When you upload an image file into database you can use directly using Image object through :LoadFromMemory( oQry:Picture ) method of image class
if want to save to disk you can use this example oQry is a query from table with flowing columns finename and file blob field

Code: Select all


//------------------------------------------------//

Function SaveToDisk( oQry )

   LOCAL nHandle
   LOCAL cDir := cGetDir( "Select Folder",;
                          CurDrive() + ":\" + GetCurDir() + "\" )
   LOCAL oQryFind

   IF ! Empty( cDir )

       cursorwait()

      oQryFind = TDolphinQry():New( "select file from files where id=" + ClipValue2Sql( oQry:Id ), oQry:oServer )

      nHandle := FCreate( cDir + "\" + AllTrim( oQry:filename ) )

      IF FError() # 0
         MsgInfo( "Error Saving File " + cDir + "\" + AllTrim( oQry:filename ) )
         RETURN
      ENDIF

      FWrite( nHandle, oQryFind:file, Len( oQryFind:file ) )
      FClose( nHandle )

      cursorarrow()
        
      cFilename := alltrim(oQry:filename)
        
      MsgInfo( "File Saved in Folder: " + cDir )

      oQryFind:End()

      if Msgyesno("Do you Want to Open File ?")
        
               ShellExecute(,"Open",'"'+cDir+"\"+cFilename+'"',,,3)
        
      endif

   ENDIF

RETURN


Nicanor Martinez M.
Auditoria y Sistemas Ltda.
MicroExpress Ltda.
FW + FWH + XHARBOUR + HARBOUR + PELLES C + XDEVSTUDIO + XEDIT + BCC + VC_X86 + VCC_X64 + MINGW + R&R Reports + FastReport + Tdolphin + ADO + MYSQL + MARIADB + ORACLE
nnicanor@yahoo.com
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Insert images in Mysql/Mariadb

Post by nageswaragunupudi »

Mr Venken

It is much simpler with FWH

Method (1)

Open the table as RowSet

Code: Select all

oRs := oCn:Rowset( "tablename" )
// position the row on the member 
oRs:foto := MEMOREAD( <fotofilename> )
oRs:Save()
 
METHOD (2)

Without opening the table.

Assume the ID of the member is 99 and the member is already in the database

Code: Select all

oCn:Update( <tablename>, "foto", { MEMOREAD( filename) }, "id -= 99" )
 
if we want to add a new record with both member name and his photo

Code: Select all

oCn:Insert( <tablename>, "name,foto", { "Mark Venken", MEMOREAD( "fotofilename" ) } )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
Marc Venken
Posts: 727
Joined: Tue Jun 14, 2016 7:51 am

Re: Insert images in Mysql/Mariadb

Post by Marc Venken »

Thanks. I gonna implement this into my program.
Marc Venken
Using: FWH 20.08 with Harbour
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: Insert images in Mysql/Mariadb

Post by fraxzi »

Hi Mr. Rao,

How about using SQL with blob for MariaDB?

Thanks,
Frances
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Insert images in Mysql/Mariadb

Post by nageswaragunupudi »

Using FWH functions is a lot easier than preparing your own SQL statement.
The field has to be created as a BLOB field only.
Regards

G. N. Rao.
Hyderabad, India
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: Insert images in Mysql/Mariadb

Post by fraxzi »

nageswaragunupudi wrote:Using FWH functions is a lot easier than preparing your own SQL statement.
The field has to be created as a BLOB field only.

I got it. Based on MariaDB Wiki, it is very much simple.
Soon, I'll get my hands on my FWH upgrade..
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
Post Reply