Connection string issues . Versions - Sage Line 50v24, PHP 7.2.2, Windows Server 2012 R2 64 bit.
Sorry if there is something I have missed - please ask for any missing info in comments. I have spent hours and hours and hours researching this and trying different things. Thank you! :-)
<?php
$user="myuser";
$pass="mypass";
$connstring="Driver={SageLine50v24};Server=localhost;Database=\\\server1\\uncpath\\companyname\\accdata\\";
echo $connstring;
$conn=odbc_connect($connstring,$user,$pass);
$sql="SELECT * FROM SALES_LEDGER";
$rs=odbc_exec($conn,$sql);
var_dump($rs);
odbc_close($conn);
?>
I believe the ODBC driver is configured ok because it works through Excel.
I have googled extensively and read probably all the SO questions on it. That pointed out things like the final backslash after ACCDATA being critical in PHP (although the ODBC driver doesnt need it in Excel or other programs;)
Variants of the above code I have tried include;
- Database local path instead of UNC path
- Driver name with and without spaces
- Server and Database with and without inverted commas
Another variant of the code I tried, however the error reporting did not return any answers;
<?php
error_reporting(E_ALL);
echo "<html>";
echo "<body>";
$user="myuser";
$pass="mypass";
$connstring="'Driver={SageLine50v24};Server=localhost;Database=\\\server1\\uncpath\\companyname\\accdata\\'";
echo $connstring;
$conn=odbc_connect($connstring,$user,$pass);
echo odbc_error($conn);
if (!$conn){exit("Connection Failed: " . $conn);}
$sql="SELECT * FROM SALES_LEDGER";
$rs=odbc_exec($conn,$sql);
var_dump($rs);
if (!$rs){exit("Error in SQL");}
echo "<table><tr>";
echo "<th>account</th>";
echo "<th>name</th></tr>";
while (odbc_fetch_row($rs))
{
$account=odbc_result($rs,"account_ref");
$coname=odbc_result($rs,"name");
echo "<tr><td>$account</td>";
echo "<td>$coname</td></tr>";
}
odbc_close($conn);
echo "</table>";
echo "</body>";
echo "</html>";
?>
This is probably over 18 months too late for you but might help someone else. I struggled for a while too when moving from Server 2008 and PHP 5.3.28 to Server 2016 and PHP 7.3.7. Both were running PHP under IIS (version 10 on Server 2016).
The following are the steps that I took to get it working followed by an example of the PHP with the connection string:
C:\Program Files\PHP\v7.3\php.ini
to includeextension=php_odbc.dll
in the[ExtensionList]
section. The library used is 32 bit and so it uses the 32-bit DSN.C:\Windows\SysWOW64\odbcad32.exe
. An example of the Data Path for the SageLine50V24 System DSN isV:\SageData\2018\accdata
The PHP then looks like: