This site had helped me a lot in the past, but now I am lost. Thanks in advance for your guidance.
I have a MySQL table that contains a Binary value, like the exampl
Note: This addresses binary data, but not encrypted data. See this answer for searching on encrypted data.
Try adding X
, x
or 0x
in front of binary data used for search:
SELECT id FROM test WHERE pid = '0xÞFÈ>ZPÎ×jRZ{æ×';
EDIT: try also this:
SELECT id FROM test WHERE BINARY pid = 'ÞFÈ>ZPÎ×jRZ{æ×';
OR
SELECT id FROM test WHERE HEX(pid) = BIN2HEX('0xÞFÈ>ZPÎ×jRZ{æ×');
as supposed here: How to select with a binary field ? (php,mysql)
IF NOTHING FROM ABOVE WORKS: Try obtaining the pid
in HEX
format, like
SELECT id, HEX(pid) pid, test FROM test
and then when searching try only:
SELECT id, test FROM test WHERE HEX(pid) = '{$my_pid}'
But I'm not sure how do You obtain the pid
data to PHP or even whether You pass the binary data into Your select - where
query... Just guessing due to the php
tag...
try:
X'' --Hex Content
mysql> SELECT x'4D7953514C';
-> 'MySQL'
The last posting from jixiang pointed me into the right direction for searching a binary field:
SELECT * FROM test WHERE yourBinaryColumn = x'binarystuffdata';
This works for me...
For me it works without quotes in the binary field
SELECT * FROM `clients_addresses` WHERE client_id = 0x4f8472e23e63404fb8f9f56