PHP 4.X and 64-Bit Integers from MySQL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David T. Ashley

    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 (dta@e3ft.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

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

    Hi david,

    Maybe you could use CONV(`columnnam e`, 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:
    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 ...

    Comment

    • David T. Ashley

      #3
      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 parsed 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 (dta@e3ft.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" <news1@phpPeanu s_RemoveThis.or gwrote in message
      news:evmde1$fa6 $1@news3.zwoll1 .ov.home.nl...
      Hi david,
      >
      Maybe you could use CONV(`columnnam e`, 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:
      >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 ...

      Comment

      Working...