Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 513575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:26:12+00:00 2026-05-13T07:26:12+00:00

I have to convert .DBF and .FPT files from Visual FoxPro to MySQL. Right

  • 0

I have to convert .DBF and .FPT files from Visual FoxPro to MySQL. Right now my script works for .DBF files, it opens and reads them with dbase_open() and dbase_get_record_with_names() and then executes the MySQL INSERT commands.

However, some fields of these .DBF files are of type MEMO and therefore stored in a separate files ending in .FPT. How do I read this file?

I have found the specifications of this filetype in MSDN, but I don’t know how I can read this file byte-wise with PHP (also, I would really prefer a simplier solution).

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:26:12+00:00Added an answer on May 13, 2026 at 7:26 am

    Alright, I have carefully studied the MSDN specifications of DBF and FPT file structures and the outcome is a beautiful PHP class which can open a DBF and (optional) an FPT memo file at the same time. This class will give you record after record and thereby fetch any memos from the memo file – if opened.

    class Prodigy_DBF {
        private $Filename, $DB_Type, $DB_Update, $DB_Records, $DB_FirstData, $DB_RecordLength, $DB_Flags, $DB_CodePageMark, $DB_Fields, $FileHandle, $FileOpened;
        private $Memo_Handle, $Memo_Opened, $Memo_BlockSize;
    
        private function Initialize() {
    
            if($this->FileOpened) {
                fclose($this->FileHandle);
            }
    
            if($this->Memo_Opened) {
                fclose($this->Memo_Handle);
            }
    
            $this->FileOpened = false;
            $this->FileHandle = NULL;
            $this->Filename = NULL;
            $this->DB_Type = NULL;
            $this->DB_Update = NULL;
            $this->DB_Records = NULL;
            $this->DB_FirstData = NULL;
            $this->DB_RecordLength = NULL;
            $this->DB_CodePageMark = NULL;
            $this->DB_Flags = NULL;
            $this->DB_Fields = array();
    
            $this->Memo_Handle = NULL;
            $this->Memo_Opened = false;
            $this->Memo_BlockSize = NULL;
        }
    
        public function __construct($Filename, $MemoFilename = NULL) {
            $this->Prodigy_DBF($Filename, $MemoFilename);
        }
    
        public function Prodigy_DBF($Filename, $MemoFilename = NULL) {
            $this->Initialize();
            $this->OpenDatabase($Filename, $MemoFilename);
        }
    
        public function OpenDatabase($Filename, $MemoFilename = NULL) {
            $Return = false;
            $this->Initialize();
    
            $this->FileHandle = fopen($Filename, "r");
            if($this->FileHandle) {
                // DB Open, reading headers
                $this->DB_Type = dechex(ord(fread($this->FileHandle, 1)));
                $LUPD = fread($this->FileHandle, 3);
                $this->DB_Update = ord($LUPD[0])."/".ord($LUPD[1])."/".ord($LUPD[2]);
                $Rec = unpack("V", fread($this->FileHandle, 4));
                $this->DB_Records = $Rec[1];
                $Pos = fread($this->FileHandle, 2);
                $this->DB_FirstData = (ord($Pos[0]) + ord($Pos[1]) * 256);
                $Len = fread($this->FileHandle, 2);
                $this->DB_RecordLength = (ord($Len[0]) + ord($Len[1]) * 256);
                fseek($this->FileHandle, 28); // Ignoring "reserved" bytes, jumping to table flags
                $this->DB_Flags = dechex(ord(fread($this->FileHandle, 1)));
                $this->DB_CodePageMark = ord(fread($this->FileHandle, 1));
                fseek($this->FileHandle, 2, SEEK_CUR);    // Ignoring next 2 "reserved" bytes
    
                // Now reading field captions and attributes
                while(!feof($this->FileHandle)) {
    
                    // Checking for end of header
                    if(ord(fread($this->FileHandle, 1)) == 13) {
                        break;  // End of header!
                    } else {
                        // Go back
                        fseek($this->FileHandle, -1, SEEK_CUR);
                    }
    
                    $Field["Name"] = trim(fread($this->FileHandle, 11));
                    $Field["Type"] = fread($this->FileHandle, 1);
                    fseek($this->FileHandle, 4, SEEK_CUR);  // Skipping attribute "displacement"
                    $Field["Size"] = ord(fread($this->FileHandle, 1));
                    fseek($this->FileHandle, 15, SEEK_CUR); // Skipping any remaining attributes
                    $this->DB_Fields[] = $Field;
                }
    
                // Setting file pointer to the first record
                fseek($this->FileHandle, $this->DB_FirstData);
    
                $this->FileOpened = true;
    
                // Open memo file, if exists
                if(!empty($MemoFilename) and file_exists($MemoFilename) and preg_match("%^(.+).fpt$%i", $MemoFilename)) {
                    $this->Memo_Handle = fopen($MemoFilename, "r");
                    if($this->Memo_Handle) {
                        $this->Memo_Opened = true;
    
                        // Getting block size
                        fseek($this->Memo_Handle, 6);
                        $Data = unpack("n", fread($this->Memo_Handle, 2));
                        $this->Memo_BlockSize = $Data[1];
                    }
                }
            }
    
            return $Return;
        }
    
        public function GetNextRecord($FieldCaptions = false) {
            $Return = NULL;
            $Record = array();
    
            if(!$this->FileOpened) {
                $Return = false;
            } elseif(feof($this->FileHandle)) {
                $Return = NULL;
            } else {
                // File open and not EOF
                fseek($this->FileHandle, 1, SEEK_CUR);  // Ignoring DELETE flag
                foreach($this->DB_Fields as $Field) {
                    $RawData = fread($this->FileHandle, $Field["Size"]);
                    // Checking for memo reference
                    if($Field["Type"] == "M" and $Field["Size"] == 4 and !empty($RawData)) {
                        // Binary Memo reference
                        $Memo_BO = unpack("V", $RawData);
                        if($this->Memo_Opened and $Memo_BO != 0) {
                            fseek($this->Memo_Handle, $Memo_BO[1] * $this->Memo_BlockSize);
                            $Type = unpack("N", fread($this->Memo_Handle, 4));
                            if($Type[1] == "1") {
                                $Len = unpack("N", fread($this->Memo_Handle, 4));
                                $Value = trim(fread($this->Memo_Handle, $Len[1]));
                            } else {
                                // Pictures will not be shown
                                $Value = "{BINARY_PICTURE}";
                            }
                        } else {
                            $Value = "{NO_MEMO_FILE_OPEN}";
                        }
                    } else {
                        $Value = trim($RawData);
                    }
    
                    if($FieldCaptions) {
                        $Record[$Field["Name"]] = $Value;
                    } else {
                        $Record[] = $Value;
                    }
                }
    
                $Return = $Record;
            }
    
            return $Return;
        }
    
        function __destruct() {
            // Cleanly close any open files before destruction
            $this->Initialize();
        }
    }
    

    The class can be used like this:

        $Test = new Prodigy_DBF("customer.DBF", "customer.FPT");
        while(($Record = $Test->GetNextRecord(true)) and !empty($Record)) {
            print_r($Record);
        }
    

    It might not be an almighty perfect class, but it works for me. Feel free to use this code, but note that the class is VERY tolerant – it doesn’t care if fread() and fseek() return true or anything else – so you might want to improve it a bit before using.

    Also note that there are many private variables like number of records, recordsize etc. which are not used at the moment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a huge collection of visual foxpro dbf files that I would like
I have a Visual Fox Pro Database (.DCX file with associated .DBF files) that
I have a form page in PHP that reads a DBF, and conditionally converts
I recently have convert my project from VB6 to VB.NET2008, after the convert here
I have to convert several full PAL videos (720x576@25) from YUV 4:2:2 to RGB,
I have a requirement where I have to convert timezone from UTC to a
I have a several DBF files generated by a third party that I need
How can I convert a .csv file into .dbf file using a python script?
I have to convert many Excell files (converted to CSV ) to the database
Sometimes I have to convert from an unsigned integer value to a float. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.