Professional Web Applications Themes

PHP 4.X and 64-Bit Integers from MySQL - MySQL

I have a box where I'm forced to use PHP before 64-bit integers became standard ... If I run a MySQL query where one of the fields returned is 64-bit integer, how do I get this into PHP as a string? My recollection is that in the result sets it "auto types" so that it is an integer, and 64-bit integers will cause problems if one tries to assign into 32 bits. P.S.--Once into PHP as a string, I would use the bcmath library to manipulate it ... -- David T. Ashley (com) http://www.e3ft.com (Consulting Home Page) http://www.dtashley.com (Personal Home ...

  1. #1

    Default PHP 4.X and 64-Bit Integers from MySQL

    I have a box where I'm forced to use PHP before 64-bit integers became
    standard ...

    If I run a MySQL query where one of the fields returned is 64-bit integer,
    how do I get this into PHP as a string? My recollection is that in the
    result sets it "auto types" so that it is an integer, and 64-bit integers
    will cause problems if one tries to assign into 32 bits.

    P.S.--Once into PHP as a string, I would use the bcmath library to
    manipulate it ...
    --
    David T. Ashley (com)
    http://www.e3ft.com (Consulting Home Page)
    http://www.dtashley.com (Personal Home Page)
    http://gpl.e3ft.com (GPL Publications and Projects)


    David Guest

  2. #2

    Default Re: PHP 4.X and 64-Bit Integers from MySQL

    Hi david,

    Maybe you could use CONV(`columnname`, 10, 10) in your SQL to convert
    the integer to a string before it is passed to php.

    for example if the colum holding 64 bits integers is named `theInt`:

    SELECT id, CONV(theInt, 10, 10) FROM yourtable

    would return the id and theInt columns but theInt converted to a string.

    Once the string is in php you may use GMP functions for calculations
    etc., see http://nl2.php.net/manual/en/ref.gmp.php

    Success,

    Henk Verhoeven,
    www.phppeanuts.org.

    David T. Ashley schreef: 
    Henk Guest

  3. #3

    Default Re: PHP 4.X and 64-Bit Integers from MySQL

    Hi Henk,

    Thanks for the help. I will look up the CONV() function.

    A person on the MySQL mailing list suggested the CONCAT() function for the
    same purpose. If that fails, I believe that MySQL has an explicit CAST()
    function that should definitely work.

    And, if that fails, there would seem to be two other options:

    a)Looking for a MySQL operator that will manipulate the integer into
    something that can't be pd as an integer, something like "95" becomes
    "S95" or even something like "IE" (9th letter, 5th letter).

    b)Storing a field in parallel with the 64-bit integer that is definitely
    text and contains the value in a different form.

    So, I have a lot to try!

    Thanks!
    --
    David T. Ashley (com)
    http://www.e3ft.com (Consulting Home Page)
    http://www.dtashley.com (Personal Home Page)
    http://gpl.e3ft.com (GPL Publications and Projects)

    "Henk verhoeven" <org> wrote in message
    news:evmde1$fa6$zwoll1.ov.home.nl... [/ref]


    David Guest

Similar Threads

  1. #39643 [NEW]: Integers selected from a MySQL-database are treated as strings
    By harmen_php_net at xtremesf dot nl in forum PHP Bugs
    Replies: 2
    Last Post: November 27th, 03:23 PM
  2. Replies: 0
    Last Post: November 27th, 02:57 PM
  3. Replies: 6
    Last Post: September 19th, 08:28 AM
  4. Converting integers to datetime
    By Peter in forum MySQL
    Replies: 3
    Last Post: November 3rd, 02:37 PM
  5. prog for g.c.d. of 2 integers
    By Van in forum Ruby
    Replies: 16
    Last Post: December 15th, 10:20 AM

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