我在我的电脑上设置了Sage Line 50 ODBC驱动程序,并在同一台机器上使用XAMPP php服务器用PHP查询sage数据库。
以下是查询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;
}
现在,查询实际上可以正常工作并检索数据。然而,它在大多数情况下都看起来很垃圾,并且有奇怪的字符而不是值。
例如:
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�
)
任何人都可以就可能发生这种情况的原因提出任何建议,也许是否有更好的方法可以做到这一点。
欢迎任何想法或经验。
此致
詹姆斯
答案 0 :(得分:0)
我遇到了与此不久前完全相同的问题。我不能告诉你是什么导致它,但我可以告诉你,替换Xampp for Wamp完全解决了它。
答案 1 :(得分:0)
使用array_map('utf8_encode',$ row);