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

2019-02-22 08:27发布

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条回答
一夜七次
2楼-- · 2019-02-22 08:43

Answering my own question.

Just figured out:

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

Does anyone know better solution?

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-02-22 09:02

Try below :

add BINARY in where clause.

$where = "where BINARY ID = '$aid'";
$query = "SELECT * FROM X ".$where;
查看更多
登录 后发表回答