ksn_prasad Posted June 1, 2010 Share Posted June 1, 2010 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. Link to comment https://forums.phpfreaks.com/topic/203487-uploading-image-data-to-database/ Share on other sites More sharing options...
shadiadiph Posted June 1, 2010 Share Posted June 1, 2010 uploading images to a database and then reading them is a real pain, it is easier to just save the file name in the database and save the image to a folder and call it using the file name from the database. Link to comment https://forums.phpfreaks.com/topic/203487-uploading-image-data-to-database/#findComment-1066045 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.