Php with MSSQL displays raw data from varbinary field

I am trying to display raw data from varbinary field on SQL server in php. I want to return exactly what I have in SQL Server (0x00000etc.), But it seems to do some kind of conversion and return me something like) T¡òaýCž "V ° Ø '© O

Hope this makes sense to someone.

thanks

0
source share
1 answer

The printout of data is always interpreted as character data when displayed in a browser. If you want to get an accurate representation of the HEX or BIN data, you will need to convert it either when selecting data using: HEX ()

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

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

If you cannot convert data at the mysql level (there may be many reasons), you can use the bin2hex equivalent:

 echo bin2hex($mydata['mybinarydata']; 

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

Good luck.

+3
source

Source: https://habr.com/ru/post/1243732/


All Articles