SQL Query with binary data (PHP and MySQL)

前端 未结 4 1494
忘了有多久
忘了有多久 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...

    0 讨论(0)
  • 2020-12-03 14:38

    try:

    X''   --Hex Content
    
    mysql> SELECT x'4D7953514C';
        -> 'MySQL'
    
    0 讨论(0)
  • 2020-12-03 14:57

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

    0 讨论(0)
  • 2020-12-03 15:01

    For me it works without quotes in the binary field

    SELECT * FROM `clients_addresses` WHERE client_id = 0x4f8472e23e63404fb8f9f56
    
    0 讨论(0)
提交回复
热议问题