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

旧城冷巷雨未停 提交于 2019-12-01 17:44:54

问题


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?


回答1:


Answering my own question.

Just figured out:

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

Does anyone know better solution?




回答2:


Try below :

add BINARY in where clause.

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


来源:https://stackoverflow.com/questions/9799788/how-to-select-with-a-binary-field-php-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!