我有两个存储过程,几乎完全相同,唯一的区别是第二个过程有一个参数。参数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