Updating to memo fields in Foxpro through ODBC using PHP

Hi everyone,

In advance I wanted to thank you for your time in replying to my post. 

My company is trying to integrate their current foxpro databases with PHP.  I am using ADODB on the PHP server and connecting using an Visual Foxpro ODBC driver. We are running into an issue where foxpro doesn't allow us to update to memo fields over 255 characters.  I ran across a link, but since I am working in PHP I'm not sure if it applies to what I'm doing.

Any suggestions would be greatly appreciated.


Answer this question

Updating to memo fields in Foxpro through ODBC using PHP

  • Lakshmana Kumar K

    I think your problem is in that VFP doesn't accept any literals over 255 in length. ie:

    insert into myTable (myNotes) values (" a string over 255 in length ... ")

    fails. However this version succeeds:

    insert into myTable (myNotes) values (" a string max 255 in length ... " + "another max 255 ..." + " another max 255 ..." + ...)

    I don't know how you could do it using $blah. Maybe you could workaround it this way (put content into a file say named mymemo.txt - you'd need fullpath instead of just filename in sample):

    $recordSet = $conn->Execute("update arjobs2 set ho_notes = filetostr('myMemo.txt') where job_no = '2981332'");

    Erase mymemo.txt here

    Or via rs (as in asp sample):

    Create recordset object and set CursorType, CursorLocation,Source etc
    $recordset->Source = "SELECT ho_notes,rep_no from arjobs92 where job_no = '2981332'";
    $recordSet.Open();
    $recordset->fields("ho_notes")->value = $blah;
    $recordset->Update();

    I don't know PHP syntax and can't help further, sorry. Maybe splitting $blah into junks of max 255 would work with your UpdateBlob().

    PS: Seeing properties, methods that are not ADO connection members makes me wonder if $recordset, $conn has anything to do with ADO and under the hood if UpdateBlob is using:
    rs.Fields ("fieldname").Value = ...
    rs.Update()
    or something else like a direct ADOConn.Execute().


  • weehyong

    ODBC and ADODB ADODB uses OleDb and VFPOLEDB updates memo fields well for me. ie (ASP code):
    <%
        cSQLSelect = "select * from Employee where val(emp_id) = 5"
        dbpath = Server.MapPath("data")
        set oConnection = Server.CreateObject( "adodb.connection" )
        set oRecordSet  = Server.CreateObject( "adodb.RecordSet" )

        with oConnection
           .ConnectionString = "Provider=VFPOLEDB;data source=" & dbpath & "\"
           .Open
        end with
        with oRecordSet
          .CursorType = 2
          .CursorLocation = 3
          .LockType   = 4
          .ActiveConnection = oConnection
          .Source = cSQLSelect
          .Open
          .Fields("Notes").Value = "123456789 123456789 123456789 123456789 123456789 " & _
                 "123456789 123456789 123456789 123456789 123456789 " & _
                 "123456789 123456789 123456789 123456789 123456789 " & _
                 "123456789 123456789 123456789 123456789 123456789 " & _
                 "123456789 123456789 123456789 123456789 123456789 " & _
                 "123456789 123456789 123456789 123456789 123456789 " & _
                 "123456789 123456789 123456789 123456789 123456789 " & _
                 "123456789 123456789 123456789 123456789 123456789 " & _
                 "123456789 123456789 123456789 123456789 123456789 " & _
                 "123456789 123456789 123456789 123456789 123456789 " & _
                 "123456789 123456789 123456789 123456789 123456789 " & _
                 "123456789 123456789 123456789 123456789 123456789 " & _
                 "123456789 123456789 123456789 123456789 123456789 " & _
                 "123456789 123456789 123456789 123456789 123456789 "
          .UpdateBatch
          .Close
        end with

        set oRs = oConnection.Execute("select First_Name,Last_Name,Notes from Employee where val(emp_id) = 5")
         ' Check results
        Response.Write("<TABLE border='1'><TR><TH>First Name</TH>" & _
        "<TH>Last Name</TH><TH>Notes</TH></TR>" )
        while not oRS.eof
                Response.Write("<TR>")
                Response.Write("<TD>" & oRs.Fields(0).value & "</TD>")
                Response.Write("<TD>" & oRs.Fields(1).value & "</TD>")
                Response.Write("<TD>" & oRs.Fields(2).value & "</TD>")
                Response.Write("</TR>")
                oRs.MoveNext
        wend
        Response.Write("</TABLE><BR/>")

        oConnection.Close
        set oConnection = nothing
    %>


  • michivo

    CetinBasoz,

    Thanks for the reply, I'm not really sure that helps out.  Below, I posted the error that occurs when 255 characters is exceeded.  Maybe this will help

    37000: [Microsoft][ODBC Visual FoxPro Driver]Command contains unrecognized phrase/keyword.

    Here is my PHP code also, pretty standard.

    < php

    include('c:\adodb\adodb.inc.php');

    $driver            = "vfp";
    $server            = "foxpro";
    $user            = "*******";
    $password        = "*******";
    $database        = "c:\\inetsrv\\foxwebdll\\ho\\data\\";
    $conn            = ADONewConnection($driver); # eg. 'mysql' or 'oci8'
    $conn->debug    = true;
    $conn->Connect($server, $user, $password, $database);
    $blah = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras fringilla magna sit amet ante. Quisq Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras fringilla magna sit amet ante. Quisq Lorem ipsum dolor sit amet, consectetuer adipiscing eLorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras fringilla magna sit amet ante. Quisq Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras fringilla magna sit amet ante. Quisq Lorem ipsum dolor sit amet, consectetuer adipiscing e";

    $conn->UpdateBlob('arjobs92', 'ho_notes', $blah, 'job_no=\'2983973\'');
    $recordSet = $conn->Execute("SELECT ho_notes,rep_no from arjobs92 where job_no = '2981332'");
    if (!$recordSet)
        print $conn->ErrorMsg();
    else
    while (!$recordSet->EOF) {
        print $recordSet->fields[0].' '.$recordSet->fields[1].'<BR>';
        $recordSet->MoveNext();
    }

    $recordSet->Close(); # optional
    $conn->Close();         # optional

    >

  • m_3ryan

    Maybe the question is, does anyone out there use PHP and foxpro together

  • Updating to memo fields in Foxpro through ODBC using PHP