How to select with a binary field ? (php,mysql)
Asked Answered
A

2

6

Try to select use "where" clause in a mysql statement: e.g. Table: X with a ID column which is BINARY data type. Then save in a variable in php

$aid = $row["id"];

How do i use this variable later when I try to select from table

$where = "where `ID` = '$aid'";
$query = "SELECT * FROM X ".$where;

Return 0 row.

Does anyone know why?

Architectural answered 21/3, 2012 at 6:45 Comment(2)
Why makes you say "not working"? Do you get an error? Does it not produce the results you expect? Does it produce no results?Israelite
just edited. it produces no results.Architectural
A
4

Answering my own question.

Just figured out:

$where = "where HEX(ID) = 'bin2hex($aid)'";
$query = "SELECT * FROM X ".$where;

Does anyone know better solution?

Architectural answered 21/3, 2012 at 7:0 Comment(0)
V
1

Try below :

add BINARY in where clause.

$where = "where BINARY ID = '$aid'";
$query = "SELECT * FROM X ".$where;
Valeriavalerian answered 21/3, 2012 at 6:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.