From:             james at safesearching dot com
Operating system: *
PHP version:      5.1.0b3
PHP Bug Type:     PDO related
Bug description:  truncating value when optional display width value is used

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 bug report at http://bugs.php.net/?id=34001&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=34001&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=34001&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=34001&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=34001&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=34001&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=34001&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=34001&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=34001&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=34001&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=34001&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=34001&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=34001&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=34001&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=34001&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=34001&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=34001&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=34001&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=34001&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=34001&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=34001&r=mysqlcfg

Reply via email to