简体   繁体   English

将二进制变量转换为PHP中的mySQL语句的十六进制表示形式

[英]Converting a binary variable to a hex representation for mySQL statement in PHP

I'm coding a tool to insert test data into a database. 我正在编写一种工具,用于将测试数据插入数据库。 Some of the fields are blobs which are the (mcrypt) encrypted representations of strings. 一些字段是blob,它们是字符串的(mcrypt)加密表示。

I'm creating binary variables, but can't find a way to properly output it in the format I see in PHPmyAdmin when I export (known good) data as a reference. 我正在创建二进制变量,但是当我导出(已知良好)数据作为参考时,找不到一种以PHPmyAdmin中看到的格式正确输出它的方法。

For example: 例如:

I used PHPmyAdmin to export a known string. 我使用PHPmyAdmin导出了已知字符串。 It produces a value of 0xe07861bbcaf39ad54a0b85389a9f08886997f8cafffe871b8569c2fcf3293bcc in the VALUES list. 它将在“值”列表中产生一个值0xe07861bbcaf39ad54a0b85389a9f08886997f8cafffe871b8569c2fcf3293bcc。

Running bin2hex on my binary field (which I've confirmed contains the same contents as known good data) results in a representation of 7a49e1b3d7c6357cab6b4f9c61bc4d8535c23cbc8789e28ce9321993e9372c80 在我的二进制字段上运行bin2hex(已确认其包含与已知正常数据相同的内容)会导致表示7a49e1b3d7c6357cab6b4f9c61bc4d8535c23cbc8789e28ce9321993e9372c80

I can't find any documentation on how to properly convert binary PHP data to the (hex) format that mySQL uses. 我找不到任何有关如何将二进制PHP数据正确转换为mySQL使用的(十六进制)格式的文档。 I've read the similar questions that seem related. 我已经阅读了似乎相关的类似问题。

How can I get from a binary field to the 0x.... value that PHPmyAdmin makes? 我如何从二进制字段获取PHPmyAdmin生成的0x ....值?

It's as simple as: 就像这样简单:

'0x' . bin2hex($bin)

As for the different outputs, my bet is that you are mixing up the original data. 至于不同的输出,我敢打赌,您正在混淆原始数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM