开发者

PHP, SQL Server: Using binary data with stored procedures

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 scr开发者_JAVA百科ipt, 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜