Insert images in Mysql/Mariadb

Insert images in Mysql/Mariadb

Postby Marc Venken » Fri May 26, 2017 9:33 pm

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 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Insert images in Mysql/Mariadb

Postby nnicanor » Sat May 27, 2017 4:38 am

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  Expand view


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

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
nnicanor
 
Posts: 302
Joined: Fri Apr 23, 2010 4:30 am
Location: Colombia

Re: Insert images in Mysql/Mariadb

Postby nageswaragunupudi » Sat May 27, 2017 6:40 am

Mr Venken

It is much simpler with FWH

Method (1)

Open the table as RowSet

Code: Select all  Expand view

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  Expand view

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  Expand view

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Insert images in Mysql/Mariadb

Postby Marc Venken » Sat May 27, 2017 11:43 am

Thanks. I gonna implement this into my program.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Insert images in Mysql/Mariadb

Postby fraxzi » Fri May 11, 2018 2:54 am

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
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Re: Insert images in Mysql/Mariadb

Postby nageswaragunupudi » Fri May 11, 2018 4:09 am

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
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Insert images in Mysql/Mariadb

Postby fraxzi » Fri May 11, 2018 6:06 am

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
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 53 guests