0

I have a long binary written to MySQL as long BLOB. When I read the BLOB back from the DB by my PHP app, I would like to take the first 12 bytes only as hex. I successfully converted the BLOB to hex by using bin2hex(BLOB) but don't know how to ignore the data over the first 12 bytes.

1 Answer 1

4

Are you looking for something this?

SELECT HEX(LEFT(data, 12)) partial
  FROM table1

Here is SQLFiddle demo

The BLOB and TEXT Types

BLOB values are treated as binary strings (byte strings).

Therefore you can grab first 12 bytes with LEFT() and then convert them with HEX()


I believe in Codeigniter you can do something like this

$result = $this->db
               ->select('HEX(LEFT(data, 12)) AS partial', FALSE)
               ->from('table1')
               ->get();
Sign up to request clarification or add additional context in comments.

1 Comment

I am using CodeIgniter to SELECT. I will look to see how this can be done there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.