Uploading Image data to Database
Posted: Tue Jun 01, 2010 1:19 am
In one of my web-application with PHP-MSSQL-IIS, I got a problem. Please give me some suggestion.
A database table contains a column 'icon' of type varbinary(max), where I have to insert the image data to it. There is a stored procedure to insert the data to that table. I am using mssql connector to access the database.
I read the contents of the image file to a variable using fread() or file_get_contents().
Now I made a query using mssql_init() and tried to bind the variables with the query using mssql_bind().
Here I got the problem. I don't know, how to bind the binary data. If I use SQLVARCHAR, it is not binding.
I tried to use the same after using addslashes(), still it is not working.
I tried to convert the data to Hexa decimal format using unpack() function, and then attempted to bind the data. Still it is not working.
I didn't find any other PHP constant other than SQLVARCHAR that matches to send the Binary data.
If I convert the data to Hexa Decimal using unpack function and insert the data to the table directly without using stored procedure, using mssql_query() it is working fine (remember not to enclose the icon data in single quotes, where other varchar, text, date values should be enclosed). But still I should not follow this way. I should use the stored procedure given by my database admin. Please let me know some clue, how to handle mssql_bind() to bind binary data.
A database table contains a column 'icon' of type varbinary(max), where I have to insert the image data to it. There is a stored procedure to insert the data to that table. I am using mssql connector to access the database.
I read the contents of the image file to a variable using fread() or file_get_contents().
Now I made a query using mssql_init() and tried to bind the variables with the query using mssql_bind().
Here I got the problem. I don't know, how to bind the binary data. If I use SQLVARCHAR, it is not binding.
I tried to use the same after using addslashes(), still it is not working.
I tried to convert the data to Hexa decimal format using unpack() function, and then attempted to bind the data. Still it is not working.
I didn't find any other PHP constant other than SQLVARCHAR that matches to send the Binary data.
If I convert the data to Hexa Decimal using unpack function and insert the data to the table directly without using stored procedure, using mssql_query() it is working fine (remember not to enclose the icon data in single quotes, where other varchar, text, date values should be enclosed). But still I should not follow this way. I should use the stored procedure given by my database admin. Please let me know some clue, how to handle mssql_bind() to bind binary data.