使用php odbc_prepare和odbc_execute我发现它经常会给我以下错误:
odbc_execute():没有足够的参数(1应该是2)给定
我很乐意我提供足够的参数,例如:
$sql = "
DECLARE @pk VARCHAR(50);
SET @pk = (SELECT TOP(1) Col_name(ic.object_id, ic.column_id) AS ColumnName
FROM sys.indexes AS i
INNER JOIN sys.index_columns AS ic
INNER JOIN sys.columns AS c
ON ic.object_id = c.object_id
AND ic.column_id = c.column_id
ON i.object_id = ic.object_id
AND i.index_id = ic.index_id
WHERE i.is_primary_key = 1
AND ic.object_id = Object_id(?));
SELECT @pk AS pk;";
$params = ['customers'];
$statement = odbc_prepare($link,$sql);
odbc_execute($statement,$params);
我疯了吗?它告诉我我需要2个参数,但我构建的查询只需要一个?。
我发现如果我将一个额外的项添加到只有null的参数数组中,它会欺骗它认为它具有它需要的2并正确执行。
一些说明: 我们使用的是PHP 5.5.5,SQL Server 2012和ODBC驱动程序Actual SQL Server