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?

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? Commented Mar 21, 2012 at 6:59
  • just edited. it produces no results. Commented Mar 21, 2012 at 7:02

2 Answers 2

4

Answering my own question.

Just figured out:

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

Does anyone know better solution?

Sign up to request clarification or add additional context in comments.

Comments

1

Try below :

add BINARY in where clause.

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

Comments

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.