Bit
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.
??? ??? ???
Changing Table Structures
[ 108 ]
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` = b '011'
WHERE CONVERT( `book`.`isbn` USING utf8 ) = '1-234567-89-0' LIMIT 1;
The highlighted line of this query shows that the column really receives a binary
value. At browse time, the exact field value (which is 3, a meaningless value for our
purposes) is redisplayed in its binary form 011, which helps to interpret each discrete
bit value.
Pages:
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