Professional Web Applications Themes

#39643 [NEW]: Integers selected from a MySQL-database are treated as strings - PHP Bugs

From: harmen_php_net at xtremesf dot nl Operating system: PHP version: 5.2.0 PHP Bug Type: MySQLi related Bug description: Integers selected from a MySQL-database are treated as strings Description: ------------ When executing the query below, I get the wrong result. Although the database returns a integer, PHP treats it as a string. Here the relevant part of phpinfo(): MysqlI Support enabled Client API library version 5.0.27 Client API header version 5.0.27 MYSQLI_SOCKET /tmp/mysql.sock The version of the MySQL server is 5.0.27 Reproduce code: --------------- <pre> <?php $rDB = mysqli_connect('localhost', 'user', 'password', 'db'); mysqli_select_db($rDB, 'db'); $rResult = mysqli_query($rDB, 'SELECT id FROM producten ...

  1. #1

    Default #39643 [NEW]: Integers selected from a MySQL-database are treated as strings

    From: harmen_php_net at xtremesf dot nl
    Operating system:
    PHP version: 5.2.0
    PHP Bug Type: MySQLi related
    Bug description: Integers selected from a MySQL-database are treated as strings

    Description:
    ------------
    When executing the query below, I get the wrong result. Although the
    database returns a integer, PHP treats it as a string.

    Here the relevant part of phpinfo():

    MysqlI Support enabled
    Client API library version 5.0.27
    Client API header version 5.0.27
    MYSQLI_SOCKET /tmp/mysql.sock

    The version of the MySQL server is 5.0.27

    Reproduce code:
    ---------------
    <pre>
    <?php
    $rDB = mysqli_connect('localhost', 'user', 'password', 'db');
    mysqli_select_db($rDB, 'db');

    $rResult = mysqli_query($rDB, 'SELECT id FROM producten WHERE id =
    4472');

    var_dump(mysqli_fetch_array($rResult));

    echo "\n---\n";

    var_dump(mysqli_fetch_field($rResult));

    ?>
    </pre>

    Expected result:
    ----------------
    array(2) {
    [0]=>
    int(4) "4472"
    ["id"]=>
    int(4) "4472"
    }

    ---
    object(stdClass)#3 (11) {
    ["name"]=>
    string(2) "id"
    ["orgname"]=>
    string(2) "id"
    ["table"]=>
    string(9) "producten"
    ["orgtable"]=>
    string(9) "producten"
    ["def"]=>
    string(0) ""
    ["max_length"]=>
    int(4)
    ["length"]=>
    int(11)
    ["chtnr"]=>
    int(63)
    ["flags"]=>
    int(49699)
    ["type"]=>
    int(3)
    ["decimals"]=>
    int(0)
    }

    Actual result:
    --------------
    array(2) {
    [0]=>
    string(4) "4472"
    ["id"]=>
    string(4) "4472"
    }

    ---
    object(stdClass)#3 (11) {
    ["name"]=>
    string(2) "id"
    ["orgname"]=>
    string(2) "id"
    ["table"]=>
    string(9) "producten"
    ["orgtable"]=>
    string(9) "producten"
    ["def"]=>
    string(0) ""
    ["max_length"]=>
    int(4)
    ["length"]=>
    int(11)
    ["chtnr"]=>
    int(63)
    ["flags"]=>
    int(49699)
    ["type"]=>
    int(3)
    ["decimals"]=>
    int(0)
    }

    --
    Edit bug report at [url]http://bugs.php.net/?id=39643&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=39643&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=39643&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=39643&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=39643&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=39643&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=39643&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=39643&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=39643&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=39643&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=39643&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=39643&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=39643&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=39643&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=39643&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=39643&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=39643&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=39643&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=39643&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=39643&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=39643&r=mysqlcfg[/url]
    harmen_php_net at xtremesf dot nl Guest

  2. #2

    Default #39643 [Bgs->Opn]: Integers selected from a MySQL-database are treated as strings

    ID: 39643
    User updated by: harmen_php_net at xtremesf dot nl
    Reported By: harmen_php_net at xtremesf dot nl
    -Status: Bogus
    +Status: Open
    Bug Type: MySQLi related
    PHP Version: 5.2.0
    New Comment:

    I think this is a bug, because it is not listed on
    [url]http://nl3.php.net/manual/en/function.mysqli-fetch-array.php[/url].

    But, if this is not a bug, how do I solve the problem, i.e., how do I
    get the value returned as the right data type (e.g. integers as
    integers, not as strings)?


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-11-27 14:57:24] [email]derickphp.net[/email]

    Thank you for taking the time to write to us, but this is not
    a bug. Please double-check the doentation available at
    [url]http://www.php.net/manual/[/url] and the instructions on how to report
    a bug at [url]http://bugs.php.net/how-to-report.php[/url]

    ..

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

    [2006-11-27 14:51:53] harmen_php_net at xtremesf dot nl

    Description:
    ------------
    When executing the query below, I get the wrong result. Although the
    database returns a integer, PHP treats it as a string.

    Here the relevant part of phpinfo():

    MysqlI Support enabled
    Client API library version 5.0.27
    Client API header version 5.0.27
    MYSQLI_SOCKET /tmp/mysql.sock

    The version of the MySQL server is 5.0.27

    Reproduce code:
    ---------------
    <pre>
    <?php
    $rDB = mysqli_connect('localhost', 'user', 'password', 'db');
    mysqli_select_db($rDB, 'db');

    $rResult = mysqli_query($rDB, 'SELECT id FROM producten WHERE id =
    4472');

    var_dump(mysqli_fetch_array($rResult));

    echo "\n---\n";

    var_dump(mysqli_fetch_field($rResult));

    ?>
    </pre>

    Expected result:
    ----------------
    array(2) {
    [0]=>
    int(4) "4472"
    ["id"]=>
    int(4) "4472"
    }

    ---
    object(stdClass)#3 (11) {
    ["name"]=>
    string(2) "id"
    ["orgname"]=>
    string(2) "id"
    ["table"]=>
    string(9) "producten"
    ["orgtable"]=>
    string(9) "producten"
    ["def"]=>
    string(0) ""
    ["max_length"]=>
    int(4)
    ["length"]=>
    int(11)
    ["chtnr"]=>
    int(63)
    ["flags"]=>
    int(49699)
    ["type"]=>
    int(3)
    ["decimals"]=>
    int(0)
    }

    Actual result:
    --------------
    array(2) {
    [0]=>
    string(4) "4472"
    ["id"]=>
    string(4) "4472"
    }

    ---
    object(stdClass)#3 (11) {
    ["name"]=>
    string(2) "id"
    ["orgname"]=>
    string(2) "id"
    ["table"]=>
    string(9) "producten"
    ["orgtable"]=>
    string(9) "producten"
    ["def"]=>
    string(0) ""
    ["max_length"]=>
    int(4)
    ["length"]=>
    int(11)
    ["chtnr"]=>
    int(63)
    ["flags"]=>
    int(49699)
    ["type"]=>
    int(3)
    ["decimals"]=>
    int(0)
    }


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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=39643&edit=1[/url]
    harmen_php_net at xtremesf dot nl Guest

  3. #3

    Default #39643 [Opn->Bgs]: Integers selected from a MySQL-database are treated as strings

    ID: 39643
    Updated by: [email]tony2001php.net[/email]
    Reported By: harmen_php_net at xtremesf dot nl
    -Status: Open
    +Status: Bogus
    Bug Type: MySQLi related
    PHP Version: 5.2.0
    New Comment:

    This is how it is supposed to work and this is how it works from the
    very beginning.
    >how do I get the value returned as the right data type
    >(e.g. integers as integers, not as strings)?
    $int = (int)$string;


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-11-27 15:11:03] harmen_php_net at xtremesf dot nl

    I think this is a bug, because it is not listed on
    [url]http://nl3.php.net/manual/en/function.mysqli-fetch-array.php[/url].

    But, if this is not a bug, how do I solve the problem, i.e., how do I
    get the value returned as the right data type (e.g. integers as
    integers, not as strings)?

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

    [2006-11-27 14:57:24] [email]derickphp.net[/email]

    Thank you for taking the time to write to us, but this is not
    a bug. Please double-check the doentation available at
    [url]http://www.php.net/manual/[/url] and the instructions on how to report
    a bug at [url]http://bugs.php.net/how-to-report.php[/url]

    ..

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

    [2006-11-27 14:51:53] harmen_php_net at xtremesf dot nl

    Description:
    ------------
    When executing the query below, I get the wrong result. Although the
    database returns a integer, PHP treats it as a string.

    Here the relevant part of phpinfo():

    MysqlI Support enabled
    Client API library version 5.0.27
    Client API header version 5.0.27
    MYSQLI_SOCKET /tmp/mysql.sock

    The version of the MySQL server is 5.0.27

    Reproduce code:
    ---------------
    <pre>
    <?php
    $rDB = mysqli_connect('localhost', 'user', 'password', 'db');
    mysqli_select_db($rDB, 'db');

    $rResult = mysqli_query($rDB, 'SELECT id FROM producten WHERE id =
    4472');

    var_dump(mysqli_fetch_array($rResult));

    echo "\n---\n";

    var_dump(mysqli_fetch_field($rResult));

    ?>
    </pre>

    Expected result:
    ----------------
    array(2) {
    [0]=>
    int(4) "4472"
    ["id"]=>
    int(4) "4472"
    }

    ---
    object(stdClass)#3 (11) {
    ["name"]=>
    string(2) "id"
    ["orgname"]=>
    string(2) "id"
    ["table"]=>
    string(9) "producten"
    ["orgtable"]=>
    string(9) "producten"
    ["def"]=>
    string(0) ""
    ["max_length"]=>
    int(4)
    ["length"]=>
    int(11)
    ["chtnr"]=>
    int(63)
    ["flags"]=>
    int(49699)
    ["type"]=>
    int(3)
    ["decimals"]=>
    int(0)
    }

    Actual result:
    --------------
    array(2) {
    [0]=>
    string(4) "4472"
    ["id"]=>
    string(4) "4472"
    }

    ---
    object(stdClass)#3 (11) {
    ["name"]=>
    string(2) "id"
    ["orgname"]=>
    string(2) "id"
    ["table"]=>
    string(9) "producten"
    ["orgtable"]=>
    string(9) "producten"
    ["def"]=>
    string(0) ""
    ["max_length"]=>
    int(4)
    ["length"]=>
    int(11)
    ["chtnr"]=>
    int(63)
    ["flags"]=>
    int(49699)
    ["type"]=>
    int(3)
    ["decimals"]=>
    int(0)
    }


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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=39643&edit=1[/url]
    tony2001@php.net Guest

Similar Threads

  1. Replies: 0
    Last Post: November 27th, 02:57 PM
  2. #39531 [NEW]: soft evaluation between integers and strings
    By jakobsg at gmail dot com in forum PHP Bugs
    Replies: 4
    Last Post: November 20th, 12:04 AM
  3. Replies: 0
    Last Post: November 16th, 11:15 AM
  4. Replies: 0
    Last Post: March 20th, 11:43 PM
  5. #25566 [Bgs]: Casting of strings to integers is flawed, no checking for non numeric chars.
    By Jared dot Williams1 at ntlworld dot com in forum PHP Development
    Replies: 1
    Last Post: September 21st, 04:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139