我有一个如下所示的存储过程:
CREATE PROCEDURE [dbo].[StoreThing]
@pid int = 0,
@data binary(236) = NULL,
AS
BEGIN
INSERT INTO thingTable (pid, data) VALUES (@pid, @data)
END
(大大简化了,但那不是重点)
我试图从PHP脚本调用此过程,如下所示:
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;
}
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)
显然,问题是
SQLCHAR
为数据字段设置类型I。但是,由于没有SQLBINARY常量,我不确定将其设置为什么。