简体   繁体   English

PHP 连接字符串语法上的 Sage 50 ODBC

[英]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;我尝试过的上述代码的变体包括;

  1. Database local path instead of UNC path数据库本地路径而不是 UNC 路径
  2. Driver name with and without spaces带空格和不带空格的驱动程序名称
  3. 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.这对您来说可能为时已晚超过 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 示例:

  • Install Sage v24 on the server.在服务器上安装 Sage v24。 You can probably get away with only doing a server install to get the ODBC driver and DSN in place but I installed the full application.您可能只需进行服务器安装即可获得 ODBC 驱动程序和 DSN,但我安装了完整的应用程序。
  • Check that the ODBC driver extension has been added to the PHP configuration as it isn't included by default with PHP 7. eg edit 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。
  • Update the DSN (32-bit version) to point to the correct Sage data location.更新 DSN(32 位版本)以指向正确的 Sage 数据位置。 You need to use the 32-bit version of the ODBC Data Source Administrator for this (as found in 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
  • Recycle the App Pool for your website in IIS.在 IIS 中为您的网站回收应用程序池。 I don't know if this is actually necessary but it happened on the way to solving my problem.我不知道这是否真的有必要,但它发生在解决我的问题的路上。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM