Mysql Hexadecimal color code store in binary datatype.By Hardik Savani | January 7, 2016 | | 1361 Viewer | Category : PHP MySql
Share this post:
If you have thousands of record store, that time database size would be large. but you can some field can save your number of bites in the database.
you have color field then most of you choose string(6) data type and you wast 6 bites on every record, but you can save number of bites data by using BINARY(3) data type. following example through you can set data type for hexa color code with only allocate binary(3) on every records. first how to create table and assign data type with following query.
CREATE TABLE IF NOT EXISTS `colors` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`color_name` varchar(255) NOT NULL,
`color` BINARY(3) NOT NULL,
PRIMARY KEY (`id`)
when you want to insert then data at that time with using UNHEX() that function would convert in small size.
INSERT INTO `colors` (color_name, color) VALUES ('Green',UNHEX('f2a709'));
when you fetch or select all the records at that using HEX() that function would convert hexadecimal color code with full size.
SELECT color_name ,HEX(color) AS color FROM `colors`;
Try this and save db size......
- How to fetch this week records in MySql ?
- How to clear log file using command in laravel 5 ?
- PHP - Getting Started PHPUnit test with simple example
- Laravel 5.3 - Create Bootstrap Contact US Form using Form Request
- Jquery - draggable sortable table rows example demo with bootstrap
- How to resolve - No supported encrypter found. The cipher and / or key length are invalid. in Laravel 5
- How to set gmail configration for mail in Laravel?
- How to get months difference between two dates in laravel?