PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → WB21 Show Image from Mysql Database
WB21 Show Image from Mysql Database
Débuté par Julio Cesar, 12 mai 2017 04:28 - 4 réponses
Posté le 12 mai 2017 - 04:28
Hi

Im trying show images from a database in a image control but nothing is displayed.

Its a php Project.

Here is the code:

HReadSeekFirst(Chamados,ChamadosID,LOOP_CHAMADOS)
IF HFound(Chamados) THEN
FSTC_DESCRICAO = Chamados.Descricao
FSTC_SOLICITANTE = Chamados.Solicitante
EDT_RESPOSTA = Chamados.Resposta
RADIO_STATUS = Chamados.Status
IMG_ANEXO..Image = Chamados.Anexo1 <============
PopupDisplay(POPUP_CHAMADOS,popupCenter+popupFixed)
END
Posté le 12 mai 2017 - 09:44
Hi Julio,

Did you set the image type correctly in the image control description?

Kind regards,
Piet
Posté le 12 mai 2017 - 11:27
Hi Julio

First, you need to set your field in the table as a longblob type.

Code to select the image and put it in the image control:

SelectedFile is string SelectedFile = fSelect("C:\Directories", "File.jpg", ... "Selezionare un file", ... "File JPG (*.jpg)" + TAB + "*.jpg" + CR + "Tutti" + TAB + "*.*", "jpg") nIdx is int=TAB_Fotografie IF SelectedFile <> "" THEN {"IMG_Image"+nIdx}=SelectedFile END
An example of saving pictures in a database:

j is int sPath is string sSql is string dsMyQuery is Data Source bRes is boolean sSql="DELETE FROM fotografie WHERE codice='"+magazzino.codice+"'" bRes=HExecuteSQLQuery(dsMyQuery,hQueryDefault,sSql) fotografie.codice=magazzino.codice FOR j=1 TO 5 sPath={"IMG_Image"+j} IF sPath <> "" THEN fotografie.riga=j HLinkMemo(fotografie,fotografia, sPath, hMemoImg) HAdd (fotografie) END END
Hope in this help

Gianni
Posté le 12 mai 2017 - 11:28
...continue

This is the portion of code to load the pictures from database:
sSql is string dsMyQuery is Data Source bRes is boolean bDati is boolean sPath is string nId is int sSql="SELECT * FROM fotografie WHERE codice='"+magazzino.codice+"'" bRes=HExecuteSQLQuery(dsMyQuery,hQueryDefault,sSql) IF bRes THEN bDati=HReadFirst(dsMyQuery) IF bDati THEN WHILE NOT HOut (dsMyQuery) nId=dsMyQuery.riga sPath=fExeDir()+"\Photo"+nId+".JPG" HExtractMemo(dsMyQuery,fotografia,sPath) {"IMG_Image"+nId}=sPath HReadNext () END END END
Posté le 12 mai 2017 - 13:56
Hi Julio,

if you are not fans of HLinkMemo/HExtractMemo ,
another method is convert image/file to base64 before save . when retrieve make sure convert back to buffer.


IMG_ANEXO..Value = Uncrypt(Chamados.Anexo1,"",cryptNone,encodeBASE64)


if you want to view image from MysqlWorkBench

select FROM_BASE64(Chamados.Anexo1) as Anexo1 from Chamados