【发布时间】:2017-04-01 23:29:20
【问题描述】:
我有两个存储过程,几乎相同,唯一的区别是第二个有一个 in 参数。
没有参数的 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的程序样式,因此您不能将其结果用作对象 -
所以mysqli的程序风格永远不能用于带参数的存储过程,只能用于不带参数的存储过程呢?那么 mysqli 的 OOP 风格可以用这个吗?
-
你可以,但你必须确保 assoc 也使用程序样式:
$row = mysqli_fetch_assoc($result_sp_in) -
谢谢,现在我没有收到任何错误,而是一个空表。我检查了我的 in 参数在表中是否有正确的字符串
-
您能否展示一下使用 Procedural 样式的代码是什么样子的?
标签: php stored-procedures mysqli