PHP / odbc connect error

Posted on 2006-06-01
Last Modified: 2013-12-12
Do you know if Microsoft's ODBC driver supports using remote datafiles?
We setup two DSNs on our server. One pointed to a datafile directory on the harddrive (C:/Datafile) and another pointed to a remote computer's datafile directory (\\pebbles\C\Datafile which was mapped by the ODBC configuration utility to Z: so it ended up pointing to Z:\Datafile).
When we tried to do a simple odbc_connect() in our php script we get a PHP warning: odbc_connect(): SQL error: [Microsoft][ODBC dBase Driver] '(unknown)' is not a valid path.
When we use the exact same code, but with the DSN that points to our harddrive's datafile, the script works.
Any assistance would be appreciated greatly.
Question by:garvism
    LVL 40

    Accepted Solution

    ODBC is not just a Microsoft technology.

    I use ODBC to connect my web server to 3 different SQL servers on our network as well as 3 remote (through VPN to another city) SQL servers.

    All using ODBC.

    Do you have Microsoft Excel? If so, can you try using Excel's get external data facility. You may need to install Microsoft Query. This will allow you to test the ODBC connection outside of PHP, using MS technology.

    Once you've proven you can connect to the remote server, you can use the DSN in PHP.

    Also, you do not need to create a DSN. You can do all of that within PHP.

    Each ODBC source has a different string (one of the downsides to ODBC).


    MS SQL Server = Driver={SQL Server};Server={$s_name_of_server};Database={$s_name_of_database}

    and for dbase ( ...

    $r_conn = odbc_pconnect("Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=Z:/Datafile", $user_name, $password);

    I don't know if a username and a password are required for dbase.

    Author Comment

    Thanks, RQuadling.  I will certainly try your suggestions and post back when I have results.

    Author Comment

    We have had success with PHp's ADOdb connection - so I'm closing this question and assigning points to RQuadling.
    LVL 40

    Expert Comment

    There are MANY other ways to connect, they all do more or less the same thing. ODBC is not OOP, but ADOdb is via a COM interface.

    You may find that using ADOdb considerably slower than using a more local mechanism. Every time you make a request, the COM interface has to be loaded. Sure the same is true with ODBC, but with ODBC, you can use something called persistent connections. This means for a set of credentials, only 1 connection is opened for the server and all traffic uses that connection. This is faster overall. Only ISAPI and FCGI SAPI's support persistent db connections. If you are using old-style CGI (normally for IIS and others), then you cannot use persistent connections and there is probably little advantage overall.

    If you have come from VB, then ADOdb may be more familiar.

    Good luck.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to count occurrences of each item in an array.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now