2011-08-04 65 views
0
delimiter // 
create procedure sp_AttendReportCountWorkouts(OUT cnt INT) 
    begin select count(*) into cnt from workout_details; 
end; 

我已經在MySQL中創建了上述存儲過程,並且我試圖計數記錄但我無法獲得所需的值結果。以下是我的PHP頁面上的實際代碼。如何使用返回值的存儲過程返回MySQL的總記錄數

$link = mysqli_connect('localhost', 'root', '', 'icoachswim_sp'); 
if (!$link) 
{ 
    printf("Can't connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error()); 
    exit; 
} 

if ($count = mysqli_query($link,"call sp_AttendReportCountWorkouts()")) 
{ 

} 

回答

1

在你的例子中$ count只是對MySQL結果的引用。 這是一個想法如何處理該參考並獲得實際結果。

if($result = mysqli_query($link,"call sp_AttendReportCountWorkouts()")) 
{ 
$row = mysqli_fetch_array($result); 
$count = $row[0]; 
} 

更新:這只是假設所存儲的過程的示例沒有使用輸出參數:

create procedure sp_AttendReportCountWorkouts() 
begin 
select count(*) from workout_details; 
end; 

用out放慢參數是,必須爲multi_query像其他答案節目或兩個連續的呼叫:

$spResult = mysqli_query($link,"call sp_AttendReportCountWorkouts(@cnt)")); 
// process $spResult here before executing next query 
$cntResult = mysqli_query($link,"select @cnt")); 
+0

由於'(OUT cnt INT)' – VolkerK

+0

感謝您的建議,但仍然沒有獲得所需的輸出,因此無法工作。 – AJAY