MySQL 5.0.3 introduced true bit-field values. These take the same amount of space in the database as the number of bits in their definition. Let's say we have three pieces of information about each book, and each piece can only be true (1) or false (0):
Book is hard cover
Book contains a CD-ROM
Book available only in electronic format
We'll use a single BIT
field to store these three pieces of information. Therefore we add a field to the book
table:
To construct and subsequently interpret the values we store into this field, we have to think in binary, respecting the position of each bit within the field. To indicate that a book is not hard cover, contains a CD-ROM and is available only in electronic format, we would use a value of 011
.
Since version 2.11.0, phpMyAdmin handles BIT
fields in a binary way. For example, if we edit one row and set a value of 011
to the some_bits
column, the following query is sent at save time:
UPDATE `marc_book`.`book` SET `stamp` = NOW( ),
`some_bits` =...