Jump to content

blueworld

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

blueworld's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. According to the MySQL manual, [quote]BIT[(M)] A bit-field type. M indicates the number of bits per value, from 1 to 64. The default is 1 if M is omitted. This data type was added in MySQL 5.0.3 for MyISAM, and extended in 5.0.5 to MEMORY, InnoDB, and BDB. Before 5.0.3, BIT is a synonym for TINYINT(1). [/quote] You're right, it was being returned as a string. The binary data was being interpreted as ascii encoding, so I got 4 characters for my 32-bit field. I guess I have to write a function now to convert the characters into an appropriate integer. Thanks for your help!
  2. Thanks! [code]echo mysql_field_type($result, 0);[/code] returns "unknown" for me. It doesn't seem to be a string representation. I'm really puzzled by this. At this point it seems like it would be easier to just use integer fields instead of bit fields.
  3. The relevent part of the definition is: ALTER TABLE phpbb_users ADD ( warning1 BIT(32) )
  4. I'm trying to store some data to a bitfield column in MySQL 5, and then retrieve it back to an integer in PHP. Some part of the process isn't working, and I've been unable to find any helpful information in my searches. Here's my test code: [code]$query1 = "UPDATE phpbb_users SET warning1 = b'0101' WHERE user_id = 2"; mysql_query($query1); $query = "SELECT warning1 FROM phpbb_users WHERE user_id = 2"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $bitfield = $row['warning1']; echo gettype($bitfield); echo '<br>' . $bitfield; echo '<br>' . (int) $bitfield;[/code] The column warning1 is of type BIT(32). Output of this script is [code]string  0[/code] Does anybody know why I'm getting a string, and how I can get an integer?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.