Php with MSSQL display raw data from varbinary field

耗尽温柔 提交于 2019-12-14 03:20:01

问题


I am trying to display the raw data from a varbinary field in SQL server in php. I want to return exactly what I have in SQL Server (0x00000etc.) but it seems to be doing some sort of conversion and returning to me something like )T¡òaýCž«V°Ø‘©O

Hopefully this makes sense to someone.

Thank you


回答1:


Data printed out is always interpreted as character data when outputted in a browser. If you want the exact HEX or BIN data representation, you will need to convert it either when you SELECT the data using: HEX()

SELECT HEX(mydata) as hexdata FROM mytable ...

And when you output it, it will now be a string of HEX characters. I think there is an equivalent for binary format which would output 0s and 1s but i'm not sure...

If you can't convert the data at the mysql level (there can be tons of reasons) then you can use the PHP equivalent bin2hex:

echo bin2hex($mydata['mybinarydata'];

The docs for bin2hex can be found at: http://www.php.net/bin2hex

Good luck



来源:https://stackoverflow.com/questions/9115578/php-with-mssql-display-raw-data-from-varbinary-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!