none
connecting to foxpro table from asp or php

    Question

  • I am having a problem and I can't seem to find any info on the internets to help me.  I'm trying to connect to a VFP free table that is on a separate machine on the network.  I want to do it inside of either PHP or ASP.NET.  Doesn't matter which at this point.  I seem to be able to establish a connection with the table, but I get an error when I execute the query.  Example php code:

    <?php
    include('adodb.inc.php');
    include_once('adodb-pager.inc.php');
    session_start();

    $db = ADONewConnection('vfp');
    $dsn="Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=\\\\othercomputer\data\provider.dbf;Exclusive=No;";
    $db->Connect($dsn) or die('nope');
    $db->SetFetchMode(ADODB_FETCH_ASSOC);
    $query = "Select * from provider where client_id = 'X9999'";
    $rs = $db->Execute($query);
    while (!$rs->EOF) {
        print_r($rs->fields);
        $rs->MoveNext();
    }?>

    I get the following error:
    Fatal error: Call to a member function on a non-object in c:\inetpub\wwwroot\test.php on line 14

    The error is pointing to where I reference the $rs query result.  I've tried multiple names on the provider in the query string and it works if the files are on the same machine as the web server.  However, I can't have all the files on the same machine as the server.  Has anyone tried to do this?  What am I doing wrong?  Thanks in advance.

    Jason

    Wednesday, November 30, 2005 9:37 PM

Answers

  • Hi

    This example below works for me fine. Be aware of authentication what will your web server will use to access a file on another machine. This can cause lots of trouble ;)

    <?php
    $conn = new COM("ADODB.Connection");
    $conn->Open('Provider=VFPOLEDB.1;Data Source="c:\wwwroot\trans\trans.DBC";Collating Sequence=HUNGARY;');
    // SQL statement to build recordset.
    $rs = $conn->Execute("SELECT * FROM courier ORDER BY Name");
    echo "<p>List of couriers:</p><hr>";
    // Display all the values in the records set
    while (!$rs->EOF) {
        $fv = $rs->Fields("Name");
        echo $fv->value."<br>\n";
        $rs->MoveNext();
    }
    $rs->Close();
    ?>

    Tuesday, December 06, 2005 10:12 AM

All replies

  • Hi

    This example below works for me fine. Be aware of authentication what will your web server will use to access a file on another machine. This can cause lots of trouble ;)

    <?php
    $conn = new COM("ADODB.Connection");
    $conn->Open('Provider=VFPOLEDB.1;Data Source="c:\wwwroot\trans\trans.DBC";Collating Sequence=HUNGARY;');
    // SQL statement to build recordset.
    $rs = $conn->Execute("SELECT * FROM courier ORDER BY Name");
    echo "<p>List of couriers:</p><hr>";
    // Display all the values in the records set
    while (!$rs->EOF) {
        $fv = $rs->Fields("Name");
        echo $fv->value."<br>\n";
        $rs->MoveNext();
    }
    $rs->Close();
    ?>

    Tuesday, December 06, 2005 10:12 AM
  • Thanks for your reply.  I see that you are accessing the table on your own machine, which I can do as well.  The problem comes with a machine on the network.  I have my IUSR_name setup on both computers and think the permissions are setup correctly, but I'm not positive.  Can anyone post what permissions should be setup for either ASP.NET or PHP? 
    Tuesday, December 06, 2005 3:04 PM
  • hey bro;

    try to configure your ODBC and add your visual foxpro table; and you can open it in PHP using odbc_connect() function..
    to configure it: open your administrative tools; opec ODBC; system DSN add and select Visual foxpro driver and your database....
    Tuesday, February 02, 2010 12:33 AM
  • I am having a problem and I can't seem to find any info on the internets to help me.  I'm trying to connect to a VFP free table that is on a separate machine on the network.  I want to do it inside of either PHP or ASP.NET.  Doesn't matter which at this point.  I seem to be able to establish a connection with the table, but I get an error when I execute the query.  Example php code:

    <?php
    include('adodb.inc.php');
    include_once('adodb-pager.inc.php');
    session_start();

    $db = ADONewConnection('vfp');
    $dsn="Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=\\\\othercomputer\data\provider.dbf;Exclusive=No;";
    $db->Connect($dsn) or die('nope');
    $db->SetFetchMode(ADODB_FETCH_ASSOC);
    $query = "Select * from provider where client_id = 'X9999'";
    $rs = $db->Execute($query);
    while (!$rs->EOF) {
        print_r($rs->fields);
        $rs->MoveNext();
    }?>

    I get the following error:
    Fatal error: Call to a member function on a non-object in c:\inetpub\wwwroot\test.php on line 14

    The error is pointing to where I reference the $rs query result.  I've tried multiple names on the provider in the query string and it works if the files are on the same machine as the web server.  However, I can't have all the files on the same machine as the server.  Has anyone tried to do this?  What am I doing wrong?  Thanks in advance.

    Jason

    You are starting with an ADO connection but then on this line:
    $dsn="Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=\\\\othercomputer\data\provider.dbf;Exclusive=No;";

    trying to use an ODBC connection string which is not supported for VFP tables having a version later than 6. There have been tons of samples on the internet and here showing how to connect and update/insert data to VFP tables from .Net code. Some of them:
    Tuesday, February 02, 2010 12:33 PM