[英]Sage 50 ODBC on PHP connection string syntax
Connection string issues .连接字符串问题。 Versions - Sage Line 50v24, PHP 7.2.2, Windows Server 2012 R2 64 bit.版本 - Sage Line 50v24、PHP 7.2.2、Windows Server 2012 R2 64 位。
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.我相信 ODBC 驱动程序配置正常,因为它可以通过 Excel 工作。
I have googled extensively and read probably all the SO questions on it.我已经广泛搜索并阅读了所有关于它的SO问题。 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;)这指出了诸如 ACCDATA 在 PHP 中至关重要之后的最后反斜杠之类的事情(尽管 ODBC 驱动程序在 Excel 或其他程序中不需要它;)
Variants of the above code I have tried include;我尝试过的上述代码的变体包括;
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.这对您来说可能为时已晚超过 18 个月,但可能会帮助其他人。 I struggled for a while too when moving from Server 2008 and PHP 5.3.28 to Server 2016 and PHP 7.3.7.从 Server 2008 和 PHP 5.3.28 迁移到 Server 2016 和 PHP 7.3.7 时,我也挣扎了一段时间。 Both were running PHP under IIS (version 10 on Server 2016).两者都在 IIS 下运行 PHP(Server 2016 上的版本 10)。
The following are the steps that I took to get it working followed by an example of the PHP with the connection string:以下是我为使其工作而采取的步骤,然后是带有连接字符串的 PHP 示例:
C:\\Program Files\\PHP\\v7.3\\php.ini
to include extension=php_odbc.dll
in the [ExtensionList]
section.检查 ODBC 驱动程序扩展是否已添加到 PHP 配置中,因为 PHP 7 默认不包含它。例如编辑C:\\Program Files\\PHP\\v7.3\\php.ini
以包含extension=php_odbc.dll
[ExtensionList]
部分。 The library used is 32 bit and so it uses the 32-bit DSN.使用的库是 32 位的,因此它使用 32 位 DSN。C:\\Windows\\SysWOW64\\odbcad32.exe
. An example of the Data Path for the SageLine50V24 System DSN is V:\\SageData\\2018\\accdata
为此,您需要使用 32 位版本的 ODBC 数据源管理器(如C:\\Windows\\SysWOW64\\odbcad32.exe
所示。SageLine50V24 系统 DSN 的数据路径示例为V:\\SageData\\2018\\accdata
The PHP then looks like: PHP 然后看起来像:
function sage_connect(){
$uid = "username";
$pwd = "password";
if (($rConn = odbc_connect("DSN=SageLine50v24;uid=$uid;pwd=$pwd", $uid, $pwd)) === false) {
die('Unable to connect to the Sage Line 50 V24 ODBC datasource.');
}
return $rConn;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.