#34001 [Opn->Asn]: truncating value when optional display width value is used

From: Date: Wed, 31 Aug 2005 05:28:39 +0000
Subject: #34001 [Opn->Asn]: truncating value when optional display width value is used
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-84215@lists.php.net to get a copy of this message
ID: 34001 Updated by: sniper@php.net Reported By: james at safesearching dot com -Status: Open +Status: Assigned Bug Type: PDO related Operating System: * PHP Version: 5.1.0b3 -Assigned To: wez +Assigned To: iliaa New Comment: Ilia: 1) don't use the "quick fix" all the time when you just have some short comment to add. 2) Why PDO differs with the "normal" api? :) Previous Comments: ------------------------------------------------------------------------ [2005-08-30 23:08:13] james at safesearching dot com MySQL isn't doing any truncating: Reproduce code: --------------- <?php $c = new PDO( "mysql:dbname=test;host=localhost", '***', '***' ); $c->exec('CREATE TABLE IF NOT EXISTS foo (id mediumint(4), primary key (id));'); $c->exec("INSERT INTO foo VALUES (6234567);"); $stmt = $c->prepare("SELECT * FROM foo"); $stmt->execute(); print_r($stmt->fetchAll()); $c = mysql_connect('localhost', '***', '***'); mysql_select_db('test'); $r = mysql_query("SELECT * FROM foo"); while ($a = mysql_fetch_array($r)) print_r($a); ?> Actual result: -------------- Array ( [0] => Array ( [id] => 6234 [0] => 6234 ) ) Array ( [0] => 6234567 [id] => 6234567 ) Comments: --------- If MySQL was truncating the data, then the results should be the same for both APIs. ------------------------------------------------------------------------ [2005-08-30 01:09:09] iliaa@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. The pdo_mysql driver does not truncate any data, if it does occur it is done by myself itself. ------------------------------------------------------------------------ [2005-08-10 10:52:10] sniper@php.net Is the truncating supposed to happen? ------------------------------------------------------------------------ [2005-08-10 04:01:33] james at safesearching dot com Tested php5-200508100030, and the junk character issue seems to be resolved, but values from the database are still being truncated. ------------------------------------------------------------------------ [2005-08-05 02:36:43] james at safesearching dot com Description: ------------ PDO seems to be trucating the value from MySQL when using the optional display width syntax (ie, mediumint(4)). From http://dev.mysql.com/doc/mysql/en/numeric-types.html <quote> ... The display width does not constrain the range of values that can be stored in the column, nor the number of digits that are displayed for values having a width exceeding that specified for the column. </quote> I'm not sure if that is the goal of PDO here is to acutally constrain the display width, since I occasionally get junk characters after the specified length. ie: +-----------------+ | id mediumint(4) | +-----------------+ | 123456 | +-----------------+ value from PDO is '1234', but sometimes is '1234Àd' or other junk characters. Reproduce code: --------------- $c = new PDO( "mysql:dbname=test;host=localhost", '***', '***' ); // mysql mediumint // bytes: 3 // minimum: -8388608 / 0 // maximum: 8388607 / 16777215 $c->exec('CREATE TABLE IF NOT EXISTS foo (id mediumint(4), primary key (id));'); $c->exec("INSERT INTO foo VALUES (12345);"); $c->exec("INSERT INTO foo VALUES (1234567);"); $stmt = $c->prepare("SELECT * FROM foo"); $stmt->execute(); print_r($stmt->fetchAll()); Expected result: ---------------- Array ( [0] => Array ( [id] => 12345 [0] => 12345 ) [1] => Array ( [id] => 1234567 [0] => 1234567 ) ) Actual result: -------------- Array ( [0] => Array ( [id] => 1234 [0] => 1234 ) [1] => Array ( [id] => 1234 [0] => 1234 ) ) --- or sometimes ---- Array ( [0] => Array ( [id] => 1234À [0] => 1234À ) [1] => Array ( [id] => 1234ÀdL [0] => 1234ÀdL ) ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=34001&edit=1

« previous php.bugs (#84215) next »