简体   繁体   English

Sage 50 ODBC PHP编码问题

[英]Sage 50 ODBC PHP encoding issues

I have setup the Sage Line 50 ODBC driver on my PC and am using XAMPP php server on the same machine to query the sage database with PHP. 我已经在我的PC上设置了Sage Line 50 ODBC驱动程序,并在同一台计算机上使用XAMPP php服务器来使用PHP查询Sage数据库。

Here is some basic code to interrogate the Sales Ledger table: 这是一些查询Sales Ledger表的基本代码:

<?php
error_reporting(E_ERROR);

//attempt to connect to Sage Line 50 via the system DSN which is on the Sage Server
echo("Trying to connect to Sage<hr>");

if(isset($_REQUEST['account_ref']) && $_REQUEST['account_ref'] != "") {
$account_ref = $_REQUEST['account_ref'];

$odbc['dsn'] = "SAGE50";
$odbc['user'] = "manager";
$odbc['pass'] = "brand";

$conn = odbc_connect($odbc['dsn'], $odbc['user'], $odbc['pass']);
if (!$conn) {
    die("Error connecting to the ODBC database: " . odbc_errormsg());
} else {
    $obj = array();
    echo("Connected<br>");
    $query = odbc_exec($conn, "SELECT * FROM SALES_LEDGER where ACCOUNT_REF = '{$account_ref}'");

    while ($row = odbc_fetch_array($query)) {
        print_r($row);
    }
}
} else {
    return false;
}

Now, the query actually works and retrieves data. 现在,查询实际上可以工作并检索数据。 However it all looks garbage for the most part and has strange characters instead of values. 但是,大多数情况下看起来都是垃圾,并且具有奇怪的字符而不是值。

For example: 例如:

Array ( 
[�������] => [] => 
[0] => 0 
[Defaul] => Defaul 
[Open] => Open 
[T1] => T1 
[4000] => 4000 
[1] => 1 
[GB] => GB 
[0.00] => 0.00 
[30] => 30 
[2009-10-22] => 2009-10-22 
[Good] => Good 
[201x��201] => 201x��201 
[201���0�] => 201���0� 
) 

Can anyone offer any suggestions about why this may be happening and perhaps if there is a better way of doing this. 任何人都可以就为什么会发生这种情况以及是否有更好的方法提出任何建议。

Any thoughts or experience would be welcomed. 任何想法或经验都将受到欢迎。

Regards 问候

James 詹姆士

I ran into exactly the same issue as this not so long ago. 不久前,我遇到了与此完全相同的问题。 I can't tell you what causes it, but I can tell you that replacing Xampp for Wamp resolved it entirely. 我无法告诉您是什么原因造成的,但是我可以告诉您,替换Xampp for Wamp可以完全解决问题。

使用array_map('utf8_encode',$ row);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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