没有任何参数它会正常工作,但是当有参数时,会出现以下错误 -
SQLSTATE[42000]:语法错误或访问冲突:8018 [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]无效参数 4 (''):数据类型 0x23 是不推荐使用的大对象或 LOB,但已标记作为输出参数。不支持将不推荐使用的类型作为输出参数。使用当前大对象 t (SQLExecute[8018] at /builddir/build/BUILD/php-5.3.3/ext/pdo_odbc/odbc_stmt.c:254)
这运行在 Centos 6、ODBC Driver 11 for SQL Server® - RedHat Linux、unixODBC-2.3.0、MSSQL Server 2008 R2
连接字符串:
$con = new PDO("odbc:dsnName", 'sa','saa');
$con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$con->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
使用的示例存储过程:
$stmt = $con->prepare( "SET NOCOUNT ON DECLARE @return_value int
EXEC @return_value = [sp_insert_into_t_contact_test]
@paravalue = ?
SELECT 'returnV' = @return_value");
$stmt->bindParam(1, $v1 = 5, PDO::PARAM_STR, 100);
$stmt->execute();
$return =$stmt->fetch();
echo $return['returnV'];
返回“123”的简单存储过程
[dbo].[sp_insert_into_t_contact_test]
@paravalue varchar(100)
AS
return 123
附加信息 -
odbc.ini 文件 -
[dsnName]
Driver=SQL Server Native Client 11.0
Description=My Sample ODBC Database Connection
Trace=Yes
Server=192.168.2.60
Port=1433
Database=NSCDB_3
odbcinst.ini
[SQL Server Native Client 11.0]
Description=Microsoft ODBC Driver 11 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2270.0
Threading=1
UsageCount=1