douyao1994 2018-08-11 11:35 采纳率: 100%
浏览 119
已采纳

PHP MySqli如何将blob作为0x00000字符串?

I have a table for things properties. Such as id, amount, owner, attributes. The attributes is stores as blob, and could be any small information about the thing itself,. Like, the thing may have text on it, or it may has something about it that makes it more unique.

When you export a table/row in PhpMyAdmin, I get these really nice values

INSERT INTO `user_things` (`owner_id`, `id`, `thingId`, `count`, `attributes`) VALUES
(1, 6, 101, 1, 0x10c8431200);

And what I'm trying to do, is being able get information from the blob in PHP that displays the blob the same way PhpMyAdmin displayed it, so I can with PHP build a string of query there the blob value stays at a 0x00000 value.

I've tried to use this code: (mysqlQuery is a simplified function I created for mysqli queries, and that one works perfect so don't worry about that part)

$thing = mysqlQuery("SELECT * FROM `user_things` LIMIT 1;");
$blob = $thing["attributes"];

but it doesn't work very well, and I've tried base64_encode and that doesn't give me the 0x000 either.

I would highly appreciate any help on this, how I can get the blob to the same type of value that PhpMyAdmin displays it as.

  • 写回答

1条回答 默认 最新

  • dtjzpg5313 2018-08-11 13:22
    关注

    0x is just a convention for expressing hexadecimal values.

    The 0x10c8431200 hexadecimal value is the same like 72079315456 decimal value.

    You can try to convert binary data to hex with the bin2hex function.

    Example:

    $thing = mysqlQuery("SELECT * FROM `user_things` LIMIT 1;");
    $blob = $thing["attributes"];
    echo bin2hex($blog);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上