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 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案