2013-11-04 40 views
0

我的连接建立后,我可以打电话给我的存储过程:mssql_execute返回没有结果 - 更好的调试方式?

$pid = $_GET['pid']; 
$conn = mssql_connect($server, $username, $password); 
... 
mssql_select_db('mydb',$conn); 

$sproc = mssql_init('consultGetPatientData'); 
mssql_bind($sproc, '@pid', $pid, SQLINT2); 

$result = mssql_execute($sproc); 
echo mssql_num_rows($result); 
if($result){  
    $row = mssql_fetch_assoc($result);  
... 

$pid值正确传递。 的$result值存在是var_dump

resource(3) of type (mssql result) 

而且msql_num_rows($result)产量0行。

连接到数据库的用户具有足够访问consultGetPatientData存储过程:

Properties

当我手动运行存储的过程,被返回期望的结果。我

我的问题:

是否有更好的方法来调试这些类型的错误?

有什么明显的我失踪了吗?

谢谢。

编辑:根据要求存储过程的代码:

ALTER PROCEDURE [dbo].[consultGetPatientData] 
    @pid int = 0  
AS 
BEGIN 
    SET NOCOUNT ON; 

select 
    pd.pid, 
    pd.external_id, 
    pd.fname, 
    pd.lname, 
    pd.DOB, 
    pd.ss, 
    pd.sex, 
    pd.allergies, 
    pb.date, 
    pb.release 
from 
    patient_data pd 
     inner join patient_booking_data pb on pd.pid = pb.pid 
where 
    pd.pid = @pid 
    and pb.date in (
     select MAX(date) from patient_booking_data where pid = @pid 
    ) 
END 
+0

让我看看你的SP代码... – Hackerman

+0

添加存储程序。 – etm124

+0

当调试时我喜欢使用error_log()记录每一件事情,你也可以将代码包装在try-catch块中。 – meda

回答

3

更改此:

$sproc = mssql_init('consultGetPatientData'); 
mssql_bind($sproc, '@pid', $pid, SQLINT2); 

$result = mssql_execute($sproc); 
echo mssql_num_rows($result); 

要这样:

$result=mssql_query("consultGetPatientData ".$pid.""); 
echo mssql_num_rows($result); 

while($arr = mssql_fetch_assoc($result)) 
{ 
echo $arr['sex']."</br>"; 
//you can put the rest of the code to display the rest of the fields 
} 
+0

有趣的是,罗伯特。 'mssql_query'的用户工作,而不是使用'mssql_execute'。这个相同的代码被部署在另一个远程服务器上,使用'execute'工作得很好。无论如何,你的答案奏效。谢谢。 – etm124