2017-04-01 45 views
0

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

感谢

+0

您正在使用mysqli'的'程序的风格,因此你无法使用其结果作为对象 – gmc

+0

所以mysqli的过程风格永远不能与带参数的存储过程一起使用,只能使用存储过程而不带参数呢? 因此,mysqli的OOP风格将与此一起工作? – user2371684

+0

你可以,但是你必须要做的事情也是使用产品风格:'$ row = mysqli_fetch_assoc($ result_sp_in)' – gmc

回答

0

更新:试试这个:

$result_sp_in = mysqli_query($mysqli, 'CALL jokes_author("Joan Smith", @joketext, @name)'); 
$select = mysqli_query($mysqli, 'SELECT @joketext, @name'); 
while($row = mysqli_fetch_array($select)) { 
    echo "<tr><td>".$row["joketext"]."</td><td>".$row["name"]."</td></tr>"; 
} 
echo "</table>"; 
+0

我以前已经更正了我的代码,这是没有参数的sp。 它的参数,显示一个空表使用$ result_sp_in – user2371684

+0

所以sp而不是mysqli_fetch_assoc,我应该尝试与mysqli_fetch_array? 如果它不是mysqli_fetch_array参数中的$ result_sp_in,我也试过,它仍然向我显示一张空表 – user2371684

+0

您确定您的MySQL过程正常工作吗? – gmc