我有兩個存儲過程,幾乎完全相同,唯一的區別是第二個過程有一個參數。參數php中的存儲過程錯誤
沒有參數的sp工作正常會生成一個空表。我已經在本地主機服務器上測試了存儲過程,因此存儲過程沒有任何問題。
我也更正了一些代碼,我在mysqli中混合過程和oop編碼。感謝「gmc」,我糾正了這一點。 這是我的代碼:
//sp
//This store proc without in params is working
echo "<h4>Författartabellen hämtad från databasen med en store procedure</h4>";
$result_sp = mysqli_query($conn, "CALL jokes");
//loop the result set
echo "<table><tr><th>Joke</th><th>AuthorName</th></tr>";
// output data of each row
while($row = mysqli_fetch_assoc($result_sp)) {
echo "<tr><td>".$row["joketext"]."</td><td>".$row["name"]."</td></tr>";
}
echo "</table>";
// This store proc with in param is not working, returns a empty table
//run the store proc
echo "<h4>Författartabellen hämtad från databasen med en store procedure</h4>";
$result_sp_in = mysqli_query($conn, 'CALL jokes_author("Joan Smith")');
//loop the result set
echo "<table><tr><th>Joke</th><th>AuthorName</th></tr>";
// output data of each row
while($row = mysqli_fetch_array($result_sp_in)) {
echo "<tr><td>".$row["joketext"]."</td><td>".$row["name"]."</td></tr>";
}
echo "</table>";
感謝
您正在使用mysqli'的'程序的風格,因此你無法使用其結果作爲對象 – gmc
所以mysqli的過程風格永遠不能與帶參數的存儲過程一起使用,只能使用存儲過程而不帶參數呢? 因此,mysqli的OOP風格將與此一起工作? – user2371684
你可以,但是你必須要做的事情也是使用產品風格:'$ row = mysqli_fetch_assoc($ result_sp_in)' – gmc