Skip to content


Reading a Paradox DB Under Windows using XAMPP

Windows provides a Paradox Driver that when used with Access can read a *.db file by either linking or importing the table. However I found that when using ADODB and VB Script to connect to the Paradox DB a time field came out as 12:00 AM. I Googled and tried all sorts of things to get the raw milliseconds-from-midnight out of the db and not the erroneous 12:00 AM but found no solution.

I thought perhaps I could use Perl but Google was strangely silent regarding both the pro’s and con’s.

PHP has an interface to the http://pxlib.sourceforge.net methods. I tried to download PHP on it’s own and then install pxlib using pear install paradox and pecl install paradox but they all failed aswell.

Enter XAMPP. This is a easy to install bundle of MySQL, PHP, APACHE etc. Where it comes in handy for me is that it has a heap of sample scripts showing how to connect to a paradox database, query it’s properties and also export an Excel spreadsheet to a browser.

After installing XAMPP Windows 1.6.6a and spending a half day hacking on the included sample scripts and learning a few tricks from the php.net documentation. I have a PHP based query form which then passes it’s values to a PHP paradox script which in turn reads the database and returns a nicely formatted Excel spreadsheet to the calling browser.

A word of warning don’t download the WAMPP 2.2 package as I did as it doesn’t have Paradox support.

I did all this on Windows XP Pro SP2.

The form used to submit data to the PHP / Paradox script

You don’t use SELECT * to query using the paradox db methods…
When using the php methods you need to loop through the entire table.
such as …

<?php
    // path to your db
    $trandb = "C:/path/to/yourdb/dbname.db";
    // check to make sure you can create a paradox object
    // exit if not
 
    if(!$pxdoc = px_new()) {
        exit("Unable to create a px_new object");
        /* Error handling */
    }
    // open the paradox database using fopen and return a file pointer
    // "r" means readonly
    $fp = fopen($trandb, "r") or exit("Cannot open $trandb");
 
    // now use paradox method to open the file
    // pointer and assign it to the pxdoc object
    if(!px_open_fp($pxdoc, $fp)) {
        exit("px_open_fp error");
            /* Error handling */
    }
    // grab some information from the paradox db
    // $myArray = px_get_info($pxdoc);
    // if you want to print details about the db use 
    // this commented code
    // echo "DB Info: preformattag";
    // print_r($myArray);
    // echo "End DB Info. endpreformattag" ;
    // This code would write the entire db to screen
    // reset ($myArray);
    // while (list($key, $val) = each($myArray)) {
           // echo "$key => $val\n <br />";
    // }
    // do a check for the number of records in the db
    $int = px_numrecords($pxdoc);
 
    //reset my record to nothing
    $myRecord = "";
 
    // I'm looping back through the db from newest to oldest 
    // hence the $i--
    for ($i = $int - 1 ; $i > 0; $i--) {
        // get each record in turn
        $myRecord = px_get_record($pxdoc, $i) ;
        //reset the array back to it's first element
        reset ($myRecord);
        //grab the transaction date from the record 
        // so we can compare it to our constraints
        $record_date =
        strtotime(
            px_date2string ($pxdoc, $myRecord["TranDate"],"Y-m-d")
        );
        if (( $record_date >= $fromdate )
        and ( $record_date <= $todate)) {
            // now we populate the $fields array 
            // with the correct values converting
            // them if necessary
            $fields[0] = $myRecord["Customer"];
            $fields[1] = $myRecord["CustName"];
            $fields[2] = $myRecord["Vehicle"];
            $fields[3] = $myRecord["Item"];
            $fields[4] = $myRecord["Docket"];
            $fields[5] = px_date2string  (
                $pxdoc, $myRecord["TranDate"], "d/m/Y"
                );
            $fields[6] = px_timestamp2string(
                $pxdoc, $myRecord["TranTime"], "h:i:sA"
                );
            $fields[7] = $myRecord["Order"];
            $fields[8] = $myRecord["Source"];
            $fields[9] = $myRecord["SourceName"];
            $fields[10] = $myRecord["Destination"];
            $fields[11] = $myRecord["DestName"];
            $fields[12] = $myRecord["Net"];
            $fields[13] = $myRecord["CancelledDocket"];
 
            //set the pointer back to the first element of the array
 
            reset($fields);
 
            while (list($key, $val) = each($fields)) {
                //when writing to screen you 
                //can use this for creating tabs
                //tab is "\t"
                echo "<br>$key: $val";
            }
        }
 
    }
    //Close the pxlib objects
 
    px_close($pxdoc);
 
    px_delete($pxdoc);
 
    //Close the actual file
 
    fclose($fp);
 
    //not sure what this exit does but 
    // it was used in the excel writer code
    // so I include it here also
    exit;
?>

Posted in IT Tips, Microsoft Tech Tips, Open Source Apps.

Tagged with , , , .


8 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Anata says

    Could you explain more detail how to “hacking on the included sample scripts and learning a few tricks from the php.net documentation”. Or could you upload that script. Thank before and after. I’m so confused

  2. james says

    Once you have installed XAMPP the included sample scripts are located in
    :\xampp\htdocs\xampp\special\paradox\. They show how to connect and query the paradox db.

    You connect to the XAMPP installation via a webbrowser (http://ip_of_xampp_server) and there are links to all the different examples

  3. danai says

    Now I can connect to Paradox. But i don’t know how to query the Paradox table such as “SELECT * FROM tblUser”. I try to find the way in PHP.net but I found only the Paradox function.

    Could you give me the sample code of this method?

    Regards,

  4. Rommel Epino says

    Have you tried query the paradox using select? any way in php.net or do you have sample code

  5. harisrozak says

    GREAT!,Thx so much!

  6. Anil Sharma says

    I read your article and installed xampp. First, tried with 1.7.7 and then with 1.6.6. In both cases, I could not find the paradox.dll, i.e., paradox driver was not installed. What could I be doing wrong? Is it possible to email me a copy a copy of php_paradox.dll.
    Thanks,
    Anil

    • admin says

      When I look into my \xampp\readme_en.txt file I have this version “###### ApacheFriends XAMPP (Basispaket) version 1.7.0 ######”

      If you have a look under \xampp\php\ext it should be there.

      You may also have to uncomment the extension=php_paradox.dll in xampp\php\php.ini

      My php.ini extension section looks as follows:

      ;;;;;;;;;;;;;;;;;;;;;;
      ; Dynamic Extensions ;
      ;;;;;;;;;;;;;;;;;;;;;;
      ;
      ; If you wish to have an extension loaded automatically, use the following
      ; syntax:
      ;
      ;   extension=modulename.extension
      ;
      ; For example, on Windows:
      ;
      ;   extension=msql.dll
      ;
      ; ... or under UNIX:
      ;
      ;   extension=msql.so
      ;
      ; Note that it should be the name of the module only; no directory information
      ; needs to go here.  Specify the location of the extension with the
      ; extension_dir directive above.
       
       
      ; Windows Extensions
      ; Note that ODBC support is built in, so no dll is needed for it.
      ; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
      ; extension folders as well as the separate PECL DLL download (PHP 5).
      ; Be sure to appropriately set the extension_dir directive.
       
      ;extension=php_apc.dll
      ;extension=php_apd.dll
      ;extension=php_bcompiler.dll
      ;extension=php_bitset.dll
      ;extension=php_blenc.dll
      ;extension=php_bz2.dll
      ;extension=php_bz2_filter.dll
      ;extension=php_classkit.dll
      ;extension=php_cpdf.dll
      ;extension=php_crack.dll
      ;extension=php_curl.dll
      ;extension=php_cvsclient.dll
      ;extension=php_db.dll
      ;extension=php_dba.dll
      ;extension=php_dbase.dll
      ;extension=php_dbx.dll
      ;extension=php_dio.dll
      ;extension=php_docblock.dll
      ;extension=php_domxml.dll
      ;extension=php_event.dll
      ;extension=php_fdf.dll
      ;extension=php_fileinfo.dll
      ;extension=php_filepro.dll
      ;extension=php_filter.dll
      ;extension=php_fribidi.dll
      extension=php_gd2.dll
      extension=php_gettext.dll
      ;extension=php_gmp.dll
      ;extension=php_gopher.dll
      ;extension=php_hash.dll
      ;extension=php_http.dll
      ;extension=php_hyperwave.dll
      ;extension=php_ibm_db2.dll
      ;extension=php_id3.dll
      ;extension=php_ifx.dll
      ;extension=php_iisfunc.dll
      ;extension=php_imagick.dll
      extension=php_imap.dll
      ;extension=php_ingres.dll
      ;extension=php_interbase.dll
      ;extension=php_ixsfunc.dll
      ;extension=php_java.dll
      ;extension=php_json.dll
      ;extension=php_ldap.dll
      ;extension=php_lzf.dll
      ;extension=php_mailparse.dll
      ;extension=php_maxdb.dll
      extension=php_mbstring.dll
      extension=php_exif.dll
      extension=php_mcrypt.dll
      ;extension=php_mcrypt_filter.dll
      ;extension=php_memcache.dll
      ;extension=php_mhash.dll
      extension=php_mime_magic.dll
      extension=php_ming.dll
      ;extension=php_msql.dll
      extension=php_mssql.dll
      extension=php_mysql.dll
      extension=php_mysqli.dll
      ;extension=php_netools.dll
      ;extension=php_ntuser.dll
      ;extension=php_oracle.dll
      ;extension=php_oci8.dll
      ;extension=php_oggvorbis.dll
      ;extension=php_openssl.dll
      ;extension=php_parsekit.dll
      extension=php_pdf.dll
      extension=php_pdo.dll
      ;extension=php_pdo_firebird.dll
      extension=php_pdo_mssql.dll
      extension=php_pdo_mysql.dll
      ;extension=php_pdo_oci.dll
      ;extension=php_pdo_oci8.dll
      ;extension=php_pdo_odbc.dll
      ;extension=php_pdo_sqlite.dll
      ;extension=php_perl.dll
      extension=php_pgsql.dll
      ;extension=php_phpdoc.dll
      ;extension=php_pop3.dll
      ;extension=php_printer.dll
      ;extension=php_pspell.dll
      ;extension=php_radius.dll
      ;extension=php_runkit.dll
      ;extension=php_sdo.dll
      ;extension=php_sdo_das_xml.dll
      ;extension=php_shmop.dll
      ;extension=php_smtp.dll
      ;extension=php_snmp.dll
      extension=php_soap.dll
      extension=php_sockets.dll
      extension=php_sqlite.dll
      ;extension=php_ssh2.dll
      ;extension=php_stats.dll
      ;extension=php_svn.dll
      ;extension=php_sybase_ct.dll
      ;extension=php_threads.dll
      ;extension=php_tidy.dll
      ;extension=php_timezonedb.dll
      ;extension=php_translit.dll
      ;extension=php_win32ps.dll
      ;extension=php_win32scheduler.dll
      ;extension=php_win32service.dll
      ;extension=php_win32std.dll
      ;extension=php_xdebug.dll
      ;extension=php_xmlreader.dll
      extension=php_xmlrpc.dll
      ;extension=php_xmlwriter.dll
      extension=php_xsl.dll
      ;extension=php_yaz.dll ; Module make problems
      extension=php_zip.dll
      ;extension=php_zlib_filter.dll
       
      extension=php_ps.dll
      extension=php_paradox.dll



Some HTML is OK

or, reply to this post via trackback.



Page optimized by WP Minify WordPress Plugin