wooper clooper
wooper clooper

Reputation: 87

PHP array to binary data?

I need to store:

array(1,2,3,4,5);

into a mysql blob.

How can i convert this array into binary data?

Upvotes: 1

Views: 897

Answers (2)

fico7489
fico7489

Reputation: 8560

you can convert to JSON and store to db:

json_encode($array);

and when you return from db:

json_decode($array);

Upvotes: -2

Bonatti
Bonatti

Reputation: 2781

It depends mostly on how you are using those informations. IDs are usually used to identify a resource, and thus must be unique, not null and indexable.

By those standarts do not use as blob.

Mostly because search by content is slower than as native variable. Also, SQL databases sort the content of a table to ensure faster queries.

If what you need is just storing information and then using another ID to identify this resource (and they can be easily parsed to strings/numbers then do not use blob). A binary file will usually use 8 bytes per char. A number could contain the same information using less total memory. Example, 1902334123 (random keyboard smash) uses 10*8 = 80 bytes in Hard disk, while an 32-bit signed integer could hold it.

Finally, if what you need is just storing several data units, what is your problem with a sequential varchar to be read as string, as it could solve your problem

Upvotes: 3

Related Questions