Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2008

    Unanswered: ODBC connection to dbase IV?

    I am trying to figure out how to query some data out of a dbase IV (.dbf) file.

    My MySQL/PHP/Web server is running PHP 4.3.11, MySQL 4.0.24, and IIS.

    I have set a system DSN on the server for the directory that contains the dbase file. The DSN name is SASIxp, and the actual file I'm trying to connect to is ADST.DBF.

    I've found several examples of how to connect with other database types, and have used those examples in an attempt to connect to my dbase IV file, but so far, I'm not having any luck. Instead, I'm getting errors like:

    Warning: odbc_exec(): SQL error: [Microsoft][ODBC dBase Driver] The Microsoft Jet database engine could not find the object 'ADST.DBF'. Make sure the object exists and that you spell its name and the path name correctly., SQL state S0002 in SQLExecDirect in E:\InetPub\wwwroot\posa_test\includes\ on line 4952
    I'm including my sandbox code below, which includes 5 different versions of $connection_string, none of which have worked.

    Does anybody know of a good tutorial, or have any suggestions? I'm on day 3 of google searches looking for a solution, and am hoping that I can find somebody out there who has had success in opening a dbase file with PHP. I know I'm somewhat limited in what I can do with a dbase IV file (if anything???), but all I really need is to do a simple lookup; no adding, deleting or changing of any records.

    //$connection_string = 'DRIVER={Microsoft dBase Driver (*.dbf)};SERVER=<>;DATABASE=<ADST.DBF>'; 
    //$connection_string = 'DRIVER={Microsoft dBase Driver (*.dbf)};SERVER=<>;DATABASE=<SASIxp>';
    //$connection_string = 'DRIVER={Microsoft dBase Driver (*.dbf)}; SASIxp;';
    //$connection_string = 'DRIVER={Microsoft dBase Driver (*.dbf)};datasource=SASIxp;';
    $connection_string = 'DRIVER={Microsoft dBase Driver (*.dbf)}; datasource=E:\TEST\ADST.DBF;';
    $user = ''; 
    $pass = ''; 
    //$connection = odbc_connect( $connection_string, $user, $pass ); 
    $odbc = odbc_connect ($connection_string, '', '') or die('Could Not Connect to ODBC Database!');
    $strsql= 'SELECT * FROM ADST.DBF';
    $query = odbc_exec($odbc, $strsql) or die (odbc_errormsg());
    Thanks in advance for your assistance!:

  2. #2
    Join Date
    Mar 2007
    Assuming your odbc_connect is working (i.e. your $connection_string works ok) then your sql statement is probably wrong.
    SELECT * FROM <table name>
    You have put the name of the file "ADST.DBF", which I suspect is where you're going wrong.

  3. #3
    Join Date
    Feb 2009
    Another SASI user! Cool. I'm with the Clark County School District in Las Vegas and we're still on SASI.

    Here is the connection string I use to access our DB4 files from VBScript programs.

    DPath = "F:\SASIxp\Datafile\"
    Set Conn = CreateObject("ADODB.Connection")
    ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&dpath&";Extended Properties=dBase IV"
    Conn.Open ConnStr
    And aschk is correct. The table name is ADST, you don't need the dbf and more than you need to reference the MDX or DBT.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts