How can I connect to Sage from PHP in Linux?

Posted on 2009-12-16
Last Modified: 2013-12-12
Sage Version is SageLine50v10
Question by:skmanji
    LVL 57

    Expert Comment

    by:Raja Jegan R
    Try creating a DSN First for your Sage server..
    And then you can do something like the one below to connect

    $database = "DSN";
    if (!$db = @odbc_connect($database,"user","pass")) {
       echo "Could not connect to $database!\n";

    More info here:

    Author Comment

    Sage resides on a Windows PC - there is no Linux version of Sage. I want to connect from a Linux PC - so where do I put the IP of the windows PC?

    What you are suggesting may work for a windows version of PHP which is on the same machine as the Sage. But thats not whats required :(
    LVL 40

    Expert Comment


    Sage Line 50 is a peer-to-peer, windows based entry level accounting system. Not client/server. No centralized service. At the time (about 6 years ago), Line 100 was the same; peer-to-peer.


    Line 50 does have an import/export facility so you can produces CSV style files and import them into your linux box.

    I used to develop an EPOS system which could interact with Sage Line 50 and Line 100. It was written in Sage's Retrieve 4GL. It was DOS based, but ran under the Sage's Line 100 Windows runtime quite happily.

    I would NOT recommend talking directly to the Line 50 DB as it is not a normalised DB and you have to know WAY too much.

    What data are you wanting to import/export.
    LVL 40

    Expert Comment

    The EPOS system would read Stock and Customer records and provide files for Stock transactions and Sales/Nominal transactions. It was just a case of running the imports and exports in the right sequence and all was well.

    Author Comment

    We can already read from a Sage DB via ODBC drivers using Visual Foxpro (because the VFP App resides on the same PC as a Sage Installation.)

    However we are moving away from VFP to browser based apps using PHP/Linux. But its not (yet) possible to wean Accounts from Sage - so we need to be able to access the Sage DB from our remote PHP Apps to get data for reporting purposes. Currently we have to use VFP Apps.

    A solution would be to have a windows-based web server on the Sage PC and use that as a "bridge" so that any app can call the windows web server and that in turn will call the Sage via a local ODBC - but you can see its getting a bit convoluted. An ideal solution would be to access the Sage directly via ODBC from any remote location.
    LVL 40

    Accepted Solution

    Ah. Are you intending to write data back? I must admit, I never really played with their ODBC route as I believe it to be read-only. But that was a LONG time ago.

    If you have SageCover (or whatever it is now called), then maybe it is worth seeing if they have unixodbc compliant drivers. I doubt it.

    Using a proxy is probably the only way to do it.

    Or you could go IIS and PHP which is well supported now. I'm running 3 IIS7+FastCGI+PHP5.3 servers here quite happily. We have an old Retrieve 4GL app (now well over 12 years old and still going), but I convert the data to MS SQL (over 7.5 million rows - 2.5GB) nightly.

    Now there's a thought.

    If you have a tool to extract ALL the data to an SQL DB (mySQL for example) - even using PHP on the Sage PC side (no webserver, just straight PHP scripts), then you could quickly sync the data.


    Author Comment

    "...quickly sync the data." Good idea. Thx.

    Author Closing Comment

    The solution wasnt what I wanted ideally - but a reasonable compromise. It seems what I want isnt available.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 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

    20 Experts available now in Live!

    Get 1:1 Help Now