我正在尝试运行一个程序,我将发送表名以从中获取所有记录。因此我不必创建不同的程序......但我面临一些问题。< / p>
ALTER PROCEDURE [dbo].[getTableData]
-- Add the parameters for the stored procedure here
@tableName Varchar(100),
@whrFldName NVarchar(100)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @ActualTableName AS NVarchar(255)
SELECT @ActualTableName = QUOTENAME( TABLE_NAME )
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = @tableName
DECLARE @sql AS NVARCHAR(MAX)
SELECT @sql = 'SELECT * FROM ' + @ActualTableName + ' WHERE ' +
@whrFldName + ' = ''y'' ;'
--PRINT @sql
EXEC(@SQL)
END
PHP代码就是这个..
$sql ="EXEC [dbo].[getTableData] 'tbl_services','serviceStatus'";
$rst = odbc_exec($connection, $sql);
$i = 0;
while($result = odbc_fetch_array($rst))
{
$returnPageData[$i] = $result;
$i++;
}
它在服务器中执行得很好但是当我从 PHP 代码中调用它时,它会返回null。
如果我删除*
并放置字段就可以了。我已经很好地测试了我的代码,它专门为文字类型字段创建了问题..
如果我将程序更改为此,它可以正常工作..
ALTER PROCEDURE [dbo].[getTableData]
-- Add the parameters for the stored procedure here
@rowsPerPage as bigint,
@pageNum as bigint
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
WITH SQLPaging AS (
SELECT TOP(@rowsPerPage * @pageNum) ROW_NUMBER() OVER (ORDER BY creationDate DESC)
AS resultNum, *
FROM [DB_SB].[dbo].[tbl_blog] )
SELECT
blogTitle,
blogSlug,
blogImage,
substring( blogContent, 1, 210 ) AS blogContent,
creationDate,
blogAddedBy
FROM SQLPaging WITH (nolock) WHERE resultNum > ((@pageNum - 1) * @rowsPerPage)
END
但这不合逻辑..如果我每次发送字段......这不是我想要的......
任何解决方案??请帮助......
答案 0 :(得分:0)
您需要使用SQL Server Profiler来查看实际获取数据库引擎的内容。
如果从SSMS运行时存储过程正确执行,则PHP部分的某处存在问题。
您是否在使用SSMS进行测试时使用相同的数据库?可能存在一些问题......