PHP ODBC Accessing Foxpro Database

Here are the steps to prepare a development environment that utilize PHP to access Foxpro Database on Windows via Apache web server:

  1. Install XAMPP
  2. Install IDE of choice for PHP – for me, I use Netbeans 6.8 on Windows XP.  Download link:  https://netbeans.org/downloads/6.8/start.html?platform=windows&lang=en&option=all&version=6.8
  3. Install ODBC Visual Foxpro Driver
  4. If Using PHP 7, enable “extension=php_odbc.dll” from ini file.   Otherwise, you will get an undefined error when calling odbc_connect.    Also, PHP 7 generates warning on ODBC queries. (Warning: odbc_exec(): SQLColAttribute can’t handle SQL_DESC_OCTET_LENGTH: [S1091] [Microsoft][ODBC Visual FoxPro Driver]Descriptor type out of range in ) See discussion in this bug report:  https://bugs.php.net/bug.php?id=73191 Use this PHP code to turn off warning:
    error_reporting(E_ERROR | E_WARNING |E_PARSE | E_NOTICE);
  5. Connecting to database as follows:
    $dsn = "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=c:\\your database;Exclusive=NO;collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
            $this->cnx= odbc_connect($dsn,"","");

 

Note:  one can use foxpro functions in query.  For example, converting a string date to date can be written as:

$query = “SELECT ponum from table WHERE  ctod(TRIM(podate)) between {{$start_date}} and {{$end_date}}
. order by podate”;

link to foxpro functions:  https://msdn.microsoft.com/en-us/library/f2x2b62b(v=vs.80).aspx