Skip to Content
0
Former Member
Nov 30, 2011 at 01:42 PM

PHP and UNICODE problem

58 Views

Hello,

I'm using MaxDB v 7.8.02.21 (64bit) on Windows7 Home Premium with SP1 (64bit).

I want to read data in PHP v 5.3.6 (Appache 2.2.19), but I have a problem when there are some UNICODE characters in the table.

My table is:

create table "ADMIN"."T"(
	"NAME" VARCHAR (1000) UNICODE)
//
insert t set name = 'a'
//
insert t set name = 'u0103'
//
insert t set name = 'b'

The problem occurs only when there is some character which is coded on 2 bytes (example: ă = UNICODE 0103).

My PHP code looks like:

// connect
$conn = odbc_pconnect($db_name, $db_user, $db_password) or die('Error connecting to server. Server says: '.htmlspecialchars(odbc_errormsg()));
if(!$conn)
 die("Bad entry to database!");
// query
$queryDual = odbc_exec($conn,"Select * from t");
while($row = odbc_fetch_array($queryDual))
 echo $row['NAME'];
echo 'num rows: '.odbc_num_rows($queryDual);

the result is:

a

num rows :3

So it seams, that reading from database fails on character 'ă'.

It is really interesting because when I make next query:

// query
$queryDual = odbc_exec($conn,"Select 'u0103' as name from t");
while($row = odbc_fetch_array($queryDual))
 echo $row['NAME'];
echo 'num rows: '.odbc_num_rows($queryDual);

the result is:

'ă'

'ă'

'ă'

num rows :3

It seams that there is no problem to transfer 'ă' character from DB to PHP but there is some problem when 'ă' character is stored in the DB table.