Monday, October 20, 2008

Make a Connection function the MySQL database with Visual FoxPro (vfp001)

First create a table to save the settings to connect the MySQL database.

CREATE table setmysql.sys free ;
 (port c(4), server c(50),uid c(50), psw c(50), database c(50))

Notes:
port -> port to connection
server -> Server MySQL
uid -> User ID
psw -> password
database -> nama database

then fill the table with the following :

INSERT INTO setmysql ;
  (port,server,uid,psw,database) VALUES ;
  ("3306","localhost","root","123","coba")


The charging of data servers, uid, psw and the database can be adjusted with mysql database settings on your computer.

to make the step connections are:

*=====================
FUNCTION mysql_connect
*=====================
LOCAL aport,aserver,auid,apsw,adatabase
LOCAL cstr,aconnect

IF USED("setmysql")
   use in setmysql
ENDIF
USE setmysql.sys in 0 alias setmysql shared

aport=alltrim(setmysql.port)
aserver=alltrim(setmysql.server)
auid=alltrim(setmysql.uid)
apsw=alltrim(setmysql.psw)
adatabase=alltrim(setmysql.database)

cstr="DATABASE="+adatabase+";"+;
     "SERVER="+aserver+";"+;
     "port="+aport+";"+;
     "UID="+auid+";"+;
     "pwd="+apsw+";"+;
     "provider=MSDASQLR;DRIVER={MySQL ODBC 3.51 Driver};"
STORE SQLSTRINGCONNECT(cstr) TO aconnect

use in setmysql
RETURN aconnect

* main
if mysql_connect()<=0
   =messagebox("Connection Failed..!",16,"Error Detection")
else
   =messagebox("Connection Success..!",64,"Information")
endif



No comments: