开发者

How to store the php result of md5("test", true) in a BINARY field of a MySQL MyISAM table

How can I store the result of:

$store = md5("test", true);
开发者_StackOverflow社区
mysql_query(...)

in a mysql db with a string query?


If you want to store it in binary format, you should pass binary data as hex to MySQL:

$md5 = md5('test'); // Returns MD5 in HEX
mysql_query("INSERT INTO `table` (`field`) VALUES (0x" . $md5 . ")");

Don't worry about MySQL handling this as integer, it won't. So if the field is declared as BINARY/BLOB, the hexadecimal value will be interpreted as binary.


Create a BINARY(16) field with index.

$store = md5("test", true);
mysql_query("INSERT INTO `Table` (`Field`) VALUES ('$store')");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜