Koneksi Mysql Libary Dengan Foxpro (NO ODBC)

Gua lagi galau berat disuruh nikah,,muukeee gilee ane, akhirnya kegalauan pun melanda, iseng-iseng karna baca buku yang katanya ODBC lebih lambat dibandingkan ADO, terus ada lagi diforum sebelah pake delphi sih katanya aku ga pernah pake ODBC langsung akses ke libarynya Mysql katanya lebih cepat juga, cari info emnk benar delphi menyediakan koneksi seperti itu, naa terus saya cari VB6 eh rupaya ada juga, foxpro ada sih juga diforum foxite itu cuma koneksi ke databasenya saya coba sukses juga,,tapi penasaran VB kq bisa nampilkan tabelnya,, udah bongkar aja punya vb hehe bermodalkan google akhirnya perlahan walau lambat ketemu juga pake Foxpro, ini hasil copas saya

bikin file program(.prg)


PROCEDURE DeclareDLL
Declare Integer mysql_init In libmySQL_d.Dll ;
Integer mID

Declare Integer mysql_store_result In libmySQL_d.dll ;
INTEGER lMYSQL ;

Declare Integer mysql_num_fields In libmySQL_d.dll ;
INTEGER nInt ;

Declare Integer mysql_fetch_fields In libmySQL_d.dll ;
INTEGER nInt1 ;

Declare Integer mysql_num_rows In libmySQL_d.dll ;
INTEGER nInt2 ;

Declare Integer mysql_fetch_row In libmySQL_d.dll ;
INTEGER nInt3 ;

Declare Integer mysql_free_result In libmySQL_d.dll ;
INTEGER nInt4;

declare integer mysql_fetch_lengths IN libmySQL_d.dll ;
integer nInt5;

Declare Integer mysql_query In libmySQL_d.dll ;
INTEGER lMYSQL, ;
STRING cString

Declare Integer mysql_real_connect In libmySQL_d.dll ;
INTEGER lMYSQL, ;
STRING sHostName ,;
STRING sUserName,;
STRING sPassword ,;
STRING sDbName ,;
INTEGER lPortNum,;
STRING sSocketName ,;
INTEGER lFlags

DECLARE RtlMoveMemory IN Kernel32 As CopyMemory;
STRING @Dest, INTEGER Src, INTEGER nLength

Declare Integer mysql_close In libmySQL_d.Dll ;
Integer nID

DECLARE integer mysql_list_fields IN libmySQL_d.dll ;
INTEGER lMySQL, ;
string cTABLE, ;
string cWild

RETURN

FUNCTION ConectMySQL
PARAMETERS _id,_host,_user,_pass,_db,_port
MYSQLCON=mysql_real_connect(_id,_Host, _User, _Pass, _DB,_Port,"",0)
RETURN MYSQLCON
*
FUNCTION table2cursor as Integer
PARAMETERS myID, _sql, _cursor
fxml = _cursor+'.xml'
MYSQLEX = mysql_query(myID, _sql)
If ( MYSQLEX = 0)

DELETE FILE &fxml
IF FILE(fxml)
hnd = FOPEN(fxml,12)
ELSE
hnd = FCREATE(fxml)
ENDIF
=FPUTS(hnd,'<?xml version = "1.0" encoding="Windows-1252" standalone="yes"?>')
=FPUTS(hnd,'<VFPData>')

pMyRES = mysql_store_result(myID)
If (pMyRES <> 0)
nNrCamp = mysql_num_fields(pMyRES)
If nNrCamp > 0
For i = 0 To mysql_num_rows(pMyRES) - 1
pMyROW = mysql_fetch_row(pMyRES)
pmylung =  mysql_fetch_lengths(pMyRES)
*-
lbuf1 = 4*(nNrCamp+1)
cBuffer1 = REPLICATE(CHR(0),lbuf1)
= CopyMemory(@cBuffer1, pMylung, LEN(cBuffer1))

DECLARE lung[nNrCamp+1]
STORE 0 TO lung
lung[1]=(nNrCamp+1)*4
&&
nLungTot = 0
FOR z =1 TO nNrCamp
lung[z+1]=ASC(SUBSTR(cBuffer1,(z-1)*4+1,1))
nLungTot = nLungTot + lung[z+1]
ENDFOR
*
marbuf = nLungTot+(nNrCamp+1)*4+100
cBuffer = REPLICATE(CHR(0),marbuf)
z= CopyMemory(@cBuffer, pMyROW, marbuf)
=FPUTS(hnd,CHR(9)+'<'+_cursor+'>')

FOR z =1 TO nNrCamp
cmp = '<'+'camp'+ALLTRIM(STR(z))+'>'
cmp_END = '</'+'camp'+ALLTRIM(STR(z))+'>'
nLungLocal = 0
FOR j = 1 TO z
nLungLocal = nLungLocal + lung[j]
ENDFOR
=FPUTS(hnd,;
CHR(9)+CHR(9)+cmp+SUBSTR(cBuffer,nLungLocal+z,lung[z+1])+cmp_end)
ENDFOR
=FPUTS(hnd,CHR(9)+'</'+_cursor+'>')
ENDFOR
ENDIF
ENDIF

mysql_free_result (pMyRES)
=FPUTS(hnd,'</VFPData>')
=FCLOSE(hnd)
XMLTOCURSOR(fxml,'mycursor',512)
BROWSE
CLOSE DATABASES
ENDIF

RETURN  MYSQLEX

kasih nama mysql2vfp_lib.prg

bikin lagi


SET PROCEDURE TO mysql2vfp_lib
DO DeclareDLL

myID = 0
myID = mysql_init(myID)
If myID = 0
MESSAGEBOX("Error MySQL Init"+ myID)
CLEAR DLLS
RETURN
Endif

Host = "localhost"
User = "root"
Pass = "4DM1N"
DB = "simpeg_db"
Port = 3306

MYSQLCON = ConectMySQL(myID,Host, User, Pass, DB,Port)
IF MYSQLCON=0
MESSAGEBOX("Error Connect MySQL")
CLEAR DLLS
RETURN
ENDIF

MYSQLEX = table2cursor(myID,'select * from pnsmain','tabel')
IF MYSQLEX <> 0
MESSAGEBOX("Error lagi bro ...")
CLEAR DLLS
RETURN
ENDIF

kasih nama cUtama (terserah)

udah coba run cUtama maka hasilnya berupa cursor🙂

saya coba lambat ^_^ mungkin karena proses konvert dari libary > xml > cursor , mungkin aja 200 record aja butuh beberapa detik ^_^

silahakn dicopas ^_^ let’s to share

[b]Periksa dulu file libmySQL.dll di system32 apakah ada atau tidak dan kebetulan nama file dll saya adalah libmySQL_d.dll[/b]

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: