1

PHP 5.2.13, MS SQL Server 2008 R2

I have a stored procedure that looks something like this:

CREATE PROCEDURE [dbo].[StoreThing]
    @pid int = 0,
    @data binary(236) = NULL,
AS
BEGIN
    INSERT INTO thingTable (pid, data) VALUES (@pid, @data)
END

(Greatly simplified, but that's beside the point)

I'm trying to call this procedure from a PHP script, as such:

function storeThing($pid, $data) {
    global $dbconn;

    if(strlen($data) != 236) return false;

    $proc = mssql_init('StoreThing', $dbconn);

    mssql_bind($proc, '@pid', $pid, SQLINT4);
    mssql_bind($proc, '@data', $data, SQLCHAR, false, false, 236);

    $result = mssql_execute($proc);
    if(!$result) die(mssql_get_last_message());

    return true;
}

However, this is not working quite right. I get the following error when I run it:

Warning: mssql_execute() [function.mssql-execute]: message: Implicit conversion from data type char to binary is not allowed. Use the CONVERT function to run this query. (severity 16)

Obviously, the problem is the SQLCHAR type I set for the data field. However, since there is no SQLBINARY constant, I am not sure what to set it to.

Alternately, will I have to change the stored procedure to accommodate PHP? I could do that, but it seems a bit dumb.

1 Answer 1

1

You can use the Microsoft SQL Server API, see http://msdn.microsoft.com/en-us/library/cc793139%28SQL.90%29.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

Ah. At the time I wrote this question, I didn't know there was a new extension for this. I ended up modifying the stored procedure anyway (and porting the app to ASP.NET, but that's beside the point)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.