2014-10-18 31 views
0
$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)的等價物,而使用預準備語句。準備語句中的mysqli_fetch_row相當於

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

回答

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存儲過程裏面。