Googling hasn't helped a lot here. I'm trying to push a binary file into a SQL Server database from PHP using a Stored Procedure. The trouble is that when I try to bind the file, PHP throws an error:
Warning: mssql_bind() [function.mssql-bind]: Unable to set parameter in C:\inetpub\wwwroot\squidersbeta\squidersbeta6\cv_submit_send.php on line 36
Warning: mssql_execute() [function.mssql-execute]: message: Procedure or function 'UploadCV' expects parameter '@fileData', which was not supplied. (severity 16) in C:\inetpub\wwwroot\squidersbeta\squidersbeta6\cv_submit_send.php on line 39
I'm using PHP5.2 on Windows 2008 x64, using the MSSQL drivers. If possible, I'd like to keep using them, as the SQLSRV drivers don't seem to work properly for me. I discovered I'd have to push the data in as a VARCHAR, so my script reads the file in as a string, then passes it to the SP. Code fragment calling this:
$fileBinary = bin2hex(file_get_contents($_FILES['cv_file']['tmp_name']));
//Prepare to execute the Stored Procedure
$spCall = mssql_init("UploadCV", $DBhandle);
--SNIP--
mssql_bind($spCall,"@fileData",$fileBinary, SQLVARCHAR, false, false, -1); //This is the line that breaks
mssql_bind($spCall, "@fileName", $_FILES['cv_file']['name'], SQLVARCHAR);
mssql_bind($spCall, "@fileType", $_FILES['cv_file']['type'], SQLVARCHAR);
mssql_execute($spCall) or die("Uh-oh, query failed!".mssql_get_last_message());
I've tried variations of the bind() call with and without the $maxlength specified. I've seen mentions that SQLVARCHARs might be limited to 254 characters - is this true, and is there any way around it? Thanks.