rivkamak
asked on
varbinary field not working in PHP 7
I am using PHP to make a call to MSSQL server.
It is returning a field type 'varbinary' that I am using to hold the data on an image
Then I would use the hex field to convert it and display it
The code worked perfectly with PHP 5.6
Now the server has been upgraded to PHP 7.2 and now the binary field is coming back as gibberish and the hexbin is throwing an error that it's not hexdecimals.
What do I need to do to make this work now?
Thank you
It is returning a field type 'varbinary' that I am using to hold the data on an image
Then I would use the hex field to convert it and display it
$photo= hex2bin( $photo);
echo '<div class="img-outer"><img class="img img-responsive img-circle" src="data:image/jpeg;base64,'.base64_encode( $photo ).'"/></div>';
The code worked perfectly with PHP 5.6
Now the server has been upgraded to PHP 7.2 and now the binary field is coming back as gibberish and the hexbin is throwing an error that it's not hexdecimals.
What do I need to do to make this work now?
Thank you
ASKER
When I pull the data from the DB on PHP5.6 if I echo the actual $photo['field']
I get neat binary text X0000456
When I upgrade to PHP 7, it's the exact same DB call, but I get back when I echo
�O�L�J"�zdi��������x���ky��BGc��� � � � � � � � � � � � � � � � � � � � � �
ASKER
This is how I call the EXEC statement
$stmt = $conn->prepare("exec KVEVI_GetImage_IndId @IndId=?" );
$stmt->bindParam(1, $id);
$stmt->execute();
$photo = $stmt->fetch(PDO::FETCH_ASSOC);
I need the field that is returned $photo['field'] to be binary
I saw somewhere I need to include this parameter
PDO::SQLSRV_ENCODING_BINARY
I've seen online how to utilize it as an INPUT field on an Insert statement, But I can't figure out how to put it on an OUTPUT field.
Any ideas?
ASKER
Any other advice possibly on how to connect when pulling non tex values?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If not, then pull the data out of the database directly into a file using a SELECT statement.
You can test your image using the command...
Open in new window
Which should report your file is a JPEG image. This will tell you where to start debugging.