I’m trying to optimize my DB, I store 5 variables (with 0,1 is enough), and instead of creating 5 columns with one enum or tinyint each one I made an smallint.
But I found out that if I store 00111 it saves 111, this make my code fail, and I saw that zerofill is just for “fancy” viewing the DB.
I’m thinking lets store 10000 by default and first number will be 1 false, 2 true, but that’s not really pretty/solid, and substr($smallint, -4, 1); for ex. just gives you the last number it founds.
So I start disliking the smallint solution, or going for mediumint, basically for the way it works, and these variables are security related.
But before make 5 columns, I’m wondering if there is any other option.
MySQL supports an extension for optionally specifying the display width of integer data types in parentheses following the base keyword for the type. For example, INT(4) specifies an INT with a display width of four digits. This optional display width may be used by applications to display integer values having a width less than the width specified for the column by left-padding them with spaces.
.
When used in conjunction with the optional (nonstandard) attribute ZEROFILL, the default padding of spaces is replaced with zeros. For example, for a column declared as INT(4) ZEROFILL, a value of 5 is retrieved as 0005.
The ZEROFILL attribute is ignored when a column is involved in expressions or UNION queries.
If you store values larger than the display width in an integer column that has the ZEROFILL attribute, you may experience problems when MySQL generates temporary tables for some complicated joins. In these cases, MySQL assumes that the data values fit within the column display width.