Edit report at https://bugs.php.net/bug.php?id=40957&edit=1

 ID:                 40957
 Comment by:         tomasz at trejderowski dot pl
 Reported by:        gerald at copix dot org
 Summary:            PDO & UTF8 string length & truncate issues
 Status:             Bogus
 Type:               Bug
 Package:            PDO related
 Operating System:   Linux
 PHP Version:        5.2.1
 Block user comment: N
 Private report:     N

 New Comment:

Comment given by tony2...@php.net seems to be wrong, because:

1. Database store ONE bytes (because it's ISO8859 - ISO is single-byte), but 
user is trying to put TWO bytes - UTF-8 is two-byte!

2. The very same results occurs, when RETRIEVING data (SELECT).

3. Certainly PHP problem -- the very same SQLs run directly on DB (Oracle in my 
example) runs without problems, but fails in PDO.


Previous Comments:
------------------------------------------------------------------------
[2007-04-03 19:01:12] tony2...@php.net

UTF8 requires 2 bytes per character.
Your database can store only 2 bytes (because it's ISO8859), but you're trying 
to put 4 and receive the expected error.
Not PHP problem.

------------------------------------------------------------------------
[2007-03-30 09:27:32] gerald at copix dot org

I made a mistake writing the actual result, it is obviously : 

(array[0]->MYFIELD === 'é') === true
(array[0]->MYFIELD === 'éa') === false

Sorry for the typo.

------------------------------------------------------------------------
[2007-03-30 09:19:21] gerald at copix dot org

Description:
------------
Hello, 

While configured in UTF8 mode (eg with the connection string 
allRequiredInfos;charset=UTF8), when we try to get a VARCHAR2 field limited to 
X chars, PDO is assuming accents (éàè...) are 2 letters length) and then 
generates a warning if our content is X chars length (with accents) and 
truncates the end of the field.

Warning:  PDOStatement::fetchAll() [scriptAdr/function.PDOStatement-fetchAll]: 
column 0 data was too large for buffer and was truncated to fit it in 
/scriptPath.class.php on line 73

We tryed to activate mbstring extension, to use func_overload=4 with no success 
(the database itself is in ISO-8859-1).

If we try not to communicate with the database in UTF8, accents are just 
ignored (é becomes e, ...) even with correct session parameters.

Reproduce code:
---------------
Considering the table 
MYTABLE {
   MYFIELD VARCHAR2(2);
}

with one record : 
MyField 
--------
éa

$pdo = new PDO ('pdo_oci:dbname=

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = myhost)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SID = mysid)

    )

  );charset=UTF8', 'myLogin', 'myPassword');

$stmt = $pdo->doQuery ('select MYFIELD from MYTABLE');
$stmt->fetchAll (); //warning

Expected result:
----------------
(array[0]->MYFIELD === 'éa') === true;

Actual result:
--------------
(array[0]->MYFIELD === 'é') === true
(array[0]->MYFIELD === 'éa') === true



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=40957&edit=1

Reply via email to