-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sqlsrv driver - binary data encoding #287
Comments
It requires complex architecture changes, so it may will appear in Dibi 5. |
I just had the same problem when inserting binary data, but the solution can be very easy - just fix the '%bin' type for mssql.
to:
Than way, the binary data will be correctly formated as |
This is actually good idea. I verified (on a SQLServer 14 Cluster), that SQLServer types |
Btw. |
Fixed |
Description
When inserting / updating a binary data to the MSSQL database, the data (output of file_get_contents) cannot be simply inserted as string value, because it rises an encoding issue (Dibi\DriverException An error occurred translating the query string to UTF-16: No mapping for the Unicode character exists in the target multi-byte code page.).
Instead of that, the binary data have to be passed as an parameter to sqlsrv_query (or sqlsrv_prepare) in following format:
array($binaryData, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max'));
More informations can be found here https://akrabat.com/some-notes-on-sql-server-blobs-with-sqlsrv/
Steps To Reproduce
Let's say we have following table:
Following code should properly create new record, with binary data
But the driver returns the mentioned error.
Now I have to use following workaround (I want to use connection from dibi, as well as generated sql query):
The text was updated successfully, but these errors were encountered: