在准备好的语句中等效于mysqli_fetch_row

时间:2014-10-18 09:33:56

标签: php stored-procedures mysqli

$link = mysqli_connect("localhost", "root", "", "db");
                    $stmt = mysqli_prepare($link, "Call breakup_api(@inno)");                            
                    mysqli_stmt_execute($stmt);                        
                    $result = mysqli_query($link,'SELECT @inno');
                    $output = mysqli_fetch_row($result);
                    mysqli_free_result($result);                                                

                    var_dump($output);

以上是在php中调用存储过程的函数。 我能够用上面的代码执行程序,我试图用准备好的语句转换上面的内容,但是无法像上面的代码那样得到输出。有人可以告诉我在使用预准备语句时mysqli_fetch_row($ result)的等价物是什么。

$db = new dbConnect();
$this->conn = $db->connect();                          
$stmt = $this->conn->prepare("Call breakup_api(@inno);SELECT @inno;");                                                    
$stmt->execute();                          
$stmt->close();

1 个答案:

答案 0 :(得分:0)

使用mysqli_stmt::fetch

$query = "Call breakup_api";// if params  -> Call breakup_api ?, ?, ?

if ($stmt = $this->conn->prepare($query)) {

    /* execute statement */
    $stmt->execute();

    /* bind result variables */
    $stmt->bind_result($inno);

    /* fetch values */
    while ($stmt->fetch()) {
        printf ("%s (%s)\n", $inno);
    }

    /* close statement */
    $stmt->close();
}

PDO无法一次运行多个查询,因此请在存储过程中移动SELECT @inno