MSSQL and inserting binary files

wxdqz

New Member
I'm trying to store a binary file (picture) using a ODBC-connection to MS SQL Server.

$fp=fopen($bin, 'r');
$contents = fread ($fp, $bin_size);
$query_string="update TABLE ";
$query_string.="set bin='$contents' ";
$query_string.="where ID=1 ";

The problem consists of the fact that I cannot use addslashes() on MSSQL. I've tried str_replace("'", "''", $contents); but to no avail.

The error message I get is as follows:

SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Unclosed quotation mark before the character string '??., SQL state 37000 in SQLExecDirect

The field in the database is 'binary'. I've tried 'varbinary' as well.


Is there anyone out there that can help me with this problem?



Yours, Jan Aage Eriksen
 
Back
Top