Wiliam
Wiliam

Reputation: 3754

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);

mysql_query(...)

in a mysql db with a string query?

Upvotes: 0

Views: 1302

Answers (2)

DASPRiD
DASPRiD

Reputation: 1683

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.

Upvotes: 1

Alex Pliutau
Alex Pliutau

Reputation: 21957

Create a BINARY(16) field with index.

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

Upvotes: 1

Related Questions