2013-04-30 33 views
1

这是一个简单的代码,我用它来获取来自IB的数据库中的一些数据:ibase_fetch_assoc在Windows XP上返回错误

<?php 
$host = 'localhost:C:/ME/DB/test.GDB'; 
$username='SYSDBA'; 
$password='*******'; 

if (!($dbh=ibase_connect($host, $username, $password, 'ISO8859_1', 0, 1))) 
    die('Could not connect: ' . ibase_errmsg()); 

$stmt = 'SELECT * FROM DB where CODE >= 4400'; 

$sth = ibase_query($dbh, $stmt); 
$letters = array(); 
while ($row = ibase_fetch_assoc($sth)) { 
    echo $row['CODE'] . ' '; 
} 

ibase_free_result($sth); 
ibase_close($dbh); 
?> 

该代码工作正常的Windows 7,但在XP(这是其中代码应工作在生产),它返回以下错误:

ibase_fetch_assoc(): arithmetic exception, numeric overflow, or string truncation Cannot transliterate character between character sets

任何人知道如何使它发挥作用?

P.S. 文档在这里说http://www.php.net/manual/en/function.ibase-query.php

If you get some error like "arithmetic exception, numeric overflow, or string truncation. Cannot transliterate character between character sets" (this occurs when you try use some character with accents) when using this and after ibase_query() you must set the character set (i.e. ISO8859_1 or your current character set).

这是在我的情况该如何解决?如果是我该如何设置字符集?

回答

2

您需要在您的ibase会话中设置正确的字符集集。如果没有设置php遵循默认值。由于您已经设置了字符集,因此数据库中的数据可能与ISO-8859-1无效。

连接到数据库时,请将charset设置为ibase_connect中的第4个参数。 您必须设置“正确”字符集,或者在某些情况下,如果使用“无”字符集,您可以使用字符集“无”,则不会有任何字符转换并使用或多或少的原始数据。

尝试使用连接:

if (!($dbh=ibase_connect($host, $username, $password, 'NONE', 0, 1))) 
    die('Could not connect: ' . ibase_errmsg()); 
+0

'NONE' 的伎俩!谢谢! – 2013-04-30 09:27:31

相关问题