|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-07-16 07:04 UTC] max dot rault at gmail dot com
[2014-07-24 10:24 UTC] rahulpriyadarshi@php.net
[2014-07-24 10:32 UTC] max dot rault at gmail dot com
[2021-03-31 10:58 UTC] cmb@php.net
-Status: Open
+Status: Feedback
-Assigned To:
+Assigned To: cmb
[2021-03-31 10:58 UTC] cmb@php.net
[2021-04-11 04:22 UTC] pecl-dev at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 06:00:01 2025 UTC |
Description: ------------ When you fetch data with PDO::FETCH_OBJ mode you obtain an object with property names that correspond to the column names returned in the result set. So for example for this table: User : id, name you'll have an object: User->id, User->name. The problem is that with PDO_IBM, in any case PDO_IBM on ibmi, you obtain an object with property names that effectively correspond to the column names returned in the result set but also with a NUL ASCII charater (ASCII code "0") at the end ! When you var_dump the object you don't see that character at all. It is invisible. But it is obviously there. So you have in reality an object which looks like: User->id"NUL", User->name"NUL". The lengths of property names are a character longer than they should be. So if, in your code, you try to display a value, for instance the name value, usually you do: <?php echo $user->name // this code fails ?> But if you write: <?php $nameProperty = "name" . chr(0); // Concatenate the NUL code ASCII at the end echo $user->$nameProperty; // this code works ?> This is amazingly weird. There is no problem with PDO_MYSQL. I checked it. So the issue seems to come from PDO_IBM driver. Test script: --------------- $database = "I1GIGC1"; $user = "MRAULT"; $pwd = "******"; $statement = "select ADH, NOM from coperl1.cprlnoms where adh in (10002, 10050)"; try { $db = new PDO("ibm:" . $database, $user, $pwd, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_AUTOCOMMIT => true, PDO::ATTR_PERSISTENT => false ) ); $query = $db->query($statement); $cprlnoms = $query->fetchAll(PDO::FETCH_OBJ); foreach ($cprlnoms as $cprlnom) { var_dump($cprlnom); echo '<br>/* echo $cprlnom object properties as usual => Epic fail */<br>'; echo '<br>KO with $cprlnom->ADH = ' . $cprlnom->ADH; echo '<br>KO with $cprlnom->NOM = ' . $cprlnom->NOM; echo '<br><br>/* echo $cprlnom object properties with freaky NUL ASCII character at the end => WTF it works ! */<br>'; $adhProperty = "ADH" . chr(0); $nomProperty = "NOM" . chr(0); echo 'OK with $cprlnom->ADH.chr(0) = ' . $cprlnom->$adhProperty; echo '<br>OK with $cprlnom->NOM.chr(0) = ' . $cprlnom->$nomProperty; }