SQL Query with binary data (PHP and MySQL)

前端 未结 4 1506
忘了有多久
忘了有多久 2020-12-03 14:11

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

4条回答
  •  無奈伤痛
    2020-12-03 14:38

    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...

提交回复
热议问题