views:

988

answers:

2

I have a varbinary(MAX) field in a SQL Server 2005 database. I'm trying to figure out how to insert binary data (ie. an image) into that field using PHP. I'm using ODBC for the connection to the SQL Server database. I have seen a number of examples that explain this for use with a MySql database but I have not been able to get it to work with SQL Server. Thanks.

+1  A: 

Try these links:

Part 1

Part 2

Part 3

Part 4

Coentje
+1  A: 

The simple answer is: stop what you're doing.

You don't want to store binary files inside a database unless you have some very specific security issues. Instead you want to store their filenames (possibly rename the files to prevent confliction) and then store that in the database. If security is an issue, then put then in a non web folder and use your code to retrieve the file and only serve the file if the user has access to it.

Storing images or files inside a database is a waste of file space, a mis-use of databases, and not letting things do what they do best; the filesystem knows files, the database knows data.

TravisO