unsigned int

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marek Simon

    #1

    unsigned int

    I have mysql database for internal computer evidence and I store IP as
    unsigned numeric value. It is very good for computing network ranges and
    so on. But PHP do not support unsigned integer. So when I store values
    to doatabase, I must convert it to string with sprintf. When reading it,
    I get a string value with 10-digit number, bigger than maxint. I need to
    convert it to signed int and work with it as a number (for making binary
    arithmetics). I have discovered no way how to do it. Intval() or (int)
    type conversion returns maxint. Converting it in mysql is anoying too,
    because mysql cant do signed 32-bit int type conversion, only 64 bit.
    Marek
  • Marek Simon

    #2
    Re: unsigned int

    Marek Simon wrote:[color=blue]
    > I have mysql database for internal computer evidence and I store IP as
    > unsigned numeric value. It is very good for computing network ranges and
    > so on. But PHP do not support unsigned integer. So when I store values
    > to doatabase, I must convert it to string with sprintf. When reading it,
    > I get a string value with 10-digit number, bigger than maxint. I need to
    > convert it to signed int and work with it as a number (for making binary
    > arithmetics). I have discovered no way how to do it. Intval() or (int)
    > type conversion returns maxint. Converting it in mysql is anoying too,
    > because mysql cant do signed 32-bit int type conversion, only 64 bit.
    > Marek[/color]

    I've just found something.
    intVal(floatVal ($num));

    Marek

    Comment

    • Jonathan

      #3
      Re: unsigned int

      Marek Simon wrote:[color=blue]
      > I have mysql database for internal computer evidence and I store IP as
      > unsigned numeric value. It is very good for computing network ranges and
      > so on. But PHP do not support unsigned integer. So when I store values
      > to doatabase, I must convert it to string with sprintf. When reading it,
      > I get a string value with 10-digit number, bigger than maxint. I need to
      > convert it to signed int and work with it as a number (for making binary
      > arithmetics). I have discovered no way how to do it. Intval() or (int)
      > type conversion returns maxint. Converting it in mysql is anoying too,
      > because mysql cant do signed 32-bit int type conversion, only 64 bit.
      > Marek[/color]

      Have you considered using the php/nmysql build-in functions (available
      as of PHP 5.0):

      PHP:
      inet_ntop() http://nl2.php.net/manual/en/function.inet-ntop.php
      inet_pton() http://nl2.php.net/manual/en/function.inet-pton.php

      MySQL:
      INET_ATON() and INET_NTOA()
      http://dev.mysql.com/doc/refman/5.0/...functions.html

      Jonathan

      Comment

      • Marek Simon

        #4
        Re: unsigned int

        > Have you considered using the php/nmysql build-in functions (available[color=blue]
        > as of PHP 5.0):
        >
        > PHP:
        > inet_ntop() http://nl2.php.net/manual/en/function.inet-ntop.php
        > inet_pton() http://nl2.php.net/manual/en/function.inet-pton.php
        >
        > MySQL:
        > INET_ATON() and INET_NTOA()
        > http://dev.mysql.com/doc/refman/5.0/...functions.html
        >
        > Jonathan[/color]

        I do not have PHP 5.0 (only 4.3) but I will try that mysql functions. I
        did those function on my own few days ago, a bunch of text parsing and
        binary shifting, not usable for writing it into each query.
        Marek

        Comment

        Working...