The argument to integer types in MySQL has no effect on the storage of data or the range of values supported by each data type.
The argument only applies to display width, which may be used by applications as Jonathan Fingland mentions. It also comes up when used in combination with the ZEROFILL
option:
CREATE TABLE foo (
i INT(3) ZEROFILL,
j INT(6) ZEROFILL,
k INT(11) ZEROFILL
);
INSERT INTO foo (i, j, k) VALUES (123, 456, 789);
SELECT * FROM foo;
+------+--------+-------------+
| i | j | k |
+------+--------+-------------+
| 123 | 000456 | 00000000789 |
+------+--------+-------------+
See how ZEROFILL
makes sure the data is zero-padded to at least the number of digits equal to the integer type argument.
Without ZEROFILL
, the data is space-padded, but since spaces are often trimmed anyway, it's harder to see that difference.
What affect does it have on your PHP code? None. If you need to output columnar data, or space-pad or zero-pad values, it's more flexible to use sprintf()
,
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…