Question

This is a simple code that I use to fetch some data from InterBase database:

<?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);
?>

That code works fine on windows 7 but on XP (It's where the code should work in production) it returns the following error:

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

Anyone knows how to make it work?

P.S. The documentation here says 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).

Is this the solution in my case? If it is how should I set the character set?

Was it helpful?

Solution

You need to set the correct charset set on your ibase session. If not set php follows the default. Since you're already setting the charset you may have data in the database that is not valid as ISO-8859-1.

When connecting to your database, set the charset as the 4th parameter in ibase_connect. You either have to set the "correct" charset or in some cases you could use charset 'NONE' if you use 'NONE' you will not have any character conversions and use more or less raw data.

Try to connect with:

if (!($dbh=ibase_connect($host, $username, $password, 'NONE', 0, 1)))
    die('Could not connect: ' .  ibase_errmsg());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top