PHP ODBC Connection not pulling results

I'm new to Sage and ODBC connections in general, so I'm looking for a bit of help here.  I have set up a System DSN on the server, and am able to get a successful connection using PHP.  However, whenever I try to run any sort of query, it doesn't pull any results.  

Here is some code I'm working with to try and get something to display.  I do get the "Connection is successful" message, but nothing after that.   Please help!!!!

$rConn = odbc_connect("SageODBC", MyUsername, MyPassword);

if (!$rConn) {
die('Unable to connect to the Sage datasource.');
}
else
{
echo "Connection is successful<br />";

$result = odbc_tables($rConn);

$tables = array();
while (odbc_fetch_row($result))
array_push($tables, odbc_result($result, "TABLE_NAME") );

foreach( $tables as $t ) {
echo "$t\n";
}

}

  • Just tried your code on my system and it worked fine. Only difference is my connect string

    $rConn = odbc_connect("DSN=systemdsn;", "usr", "pwd") ;

    But if you are getting a connection, that shouldn't be it.

    I am running from a browser so I changed the  echo "$t<br>";  and got a nice long list of table names.

  • in reply to Dain

    If I add in the "DSN=" it gives me the Unable to Connect error message.  I'm truly stumped.  Not sure why this code isn't working on my end.  Are there any specific settings in the php.ini file that need to be set?  Or any of the System DSN settings that need to be set?

  • in reply to mcolwell

    Anyone else?  Still stumped on this one.  Why would the odbc connection not pull any results what so ever?

  • in reply to mcolwell

    A couple of things to check in Sage 100 ...

    - Is "Enable ODBC Security within Role Maintenance" enabled (System Security | Security tab)

    - If so, does the user's Role have correct ODBC permissions (Role Maintenance | ODBC Security tab)

  • in reply to wedwards

    Wedwards

    I double checked, and the user's Role does have all of the check boxes checked under the ODBC Security tab.  

  • in reply to mcolwell

    One other thought is permissions. I have had difficulty getting PHP to work from machines other than the server where SAGE is installed. As long as I run IIS with PHP on the same serve I can access files fine. I have never been able to get permissions work when trying to run them from any other server.

    We are a small company with only 25 seats so I get away with it.

    Theoretically we should not be running IIS on the same server.

  • in reply to Dain

    Even this doesn't pull a result....

                      $query = "Select 1 as test";

    $rs = odbc_exec($rConn, $query);

    odbc_fetch_row($rs);

    echo odbc_result($rs, "test");

    It makes me think there's some sort of setting somewhere that I'm missing.  Is there anything special in the php.ini file that I need to have set?   I thought I hit everything there, but maybe I didn't.  

  • in reply to mcolwell

    Ok... perhaps I'm getting somewhere.  Looks like it's definitely permissions related:  

    [ProvideX][ODBC Driver][FILEIO]Table is not accessible

  • in reply to mcolwell

    You get that sometimes when you try to pull a works table or the table is locked for processing. Have you ever thought of creating an Access database with SQL Specific Pass Through Queries with the log-in coded in and then create a DSN for that database and PHP on that?

  • in reply to BigLouie

    I was able to get past this by setting IIS and PHP up on the MAS server itself, and running the web site from that server.