Wiki Home


Namespace: VFP
Has anyone tried to interface VFP to My Sql using PHP. I have MyODBC working fine but it requires direct port access into the MySQL server. I am wondering if anyone has made an interface the will pass SQL requests to My Sql via PHP. My server offers MySQL but not direct port.

IF you are doing things at a web site with php - why not add in another abstraction layer to get to data ? look here and get the VFP libraries you need. William Sanders

I had similar problem with my ISP -- they refused to open a port, allowing My Sql access only for local scripts on their server. At that time I had no other choice but to create FoxPro and PHP modules emulating, I would say, ODBC functionality.

FoxPro class creates HTTP request containing SQL statement, My Sql database name, user name etc. and passes this request to remote PHP script. The PHP script executes SQL statement against My Sql database and returns back set of data. This set may include error codes and messages, number of rows affected, text-delimited output returned by SQL SELECT statement.

FoxPro class converts the response first into temporary ASCII file then into a regular cursor, same way as ODBC does. It worked more or less Ok, with just a few minor issues. I did not finish it to a state of a distributed solution, for that particular project it was good enough.

Here is a sample code creating and using FoxPro class communicating with sendquery.php script:
#DEFINE ccHref_SendQuery ''
#DEFINE ccDBHost ''
#DEFINE ccDBUser 'dbuser'
#DEFINE ccDBPwd  'password'
#DEFINE ccDBName 'dbtest'


mysql = CREATEOBJECT('msRequest', ccHref_SendQuery,;
	ccDBHost, ccDBUser, ccDBPwd, ccDBName)

cSql = "SELECT * FROM products WHERE category='S' ORDER BY sku"
cCursor = "csProducts"

IF mysql.ExecuteSql(cSql, cCursor) = 0
	? mysql.request_error
	? mysql.mysql_errno
	? mysql.mysql_error
	SELECT csProducts

-- Anatoliy Mogylevets
( Topic last updated: 2004.07.08 04:58:51 PM )