In an attempt to create a column with 32-bit binary numbers
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('test_binary', function (Blueprint $table) {
$table->increments('id');
$table->char('binary_number', 32)->charset('binary'); // From: https://stackoverflow.com/a/62615777/5675325
$table->timestamps();
});
}
namely
$table->char('binary_number', 32)->charset('binary');
When I view it through HeidiSQL I can see that it is of type BINARY
with size 32.
When creating the seeder to populate with the desired data, I tried
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('test_binary')->insert([
'id' => 1,
'binary_number' => 2,
'created_at' => now(),
'updated_at' => now()
]);
It turns out that if I use 2 or 101 in binary_number
, I will get the result in DB to be 2 or 101, respectively.
When I try 000000000000000000000000000000000010
(which equals 2 in 32-bit binary) and 000000000000000000000000000001100101
(which equals 101 in 32-bit binary)
'binary_number' => 00000000000000000000000000000010,
then I get the values 8 and 294977, respectively.
However, what I am looking for is for the 2 to be stored as 0000000000000000000000000000000000000010
and the 101 to be 000000000000000000000000000001100101
.