2009-11-17 27 views
1

我有一個問題,我的預處理語句似乎只返回返回的行數而不是行的值。以下是我的代碼。我確實爲此嘗試了谷歌,但它並沒有告訴我任何東西!如果有人能告訴我我做錯了什麼以及如何解決這個問題,我會非常感激。由於使用預處理語句返回特定行

$query2 = 'SELECT * FROM kids_entry WHERE email = ?'; 
$stmt2 = $connection->prepare($query2); 

// bind the user id as an integer to the first ? 
$stmt2->bind_param('s', $email); 
$stmt2->execute(); // execute the statement 

$stmt2->store_result(); // this call is required for the next operation 

while($row1 = $stmt2->fetch()){ 
    printf ("%s \n", $entries); 
} 

編輯

我也只是嘗試更換,如果用while循環和我有同樣的事情。

EDIT 2

已增加它的工作原理的新代碼,但如何將我分配這一個變量$?

回答

0

看到了PHP文檔中的例子: mysqli_stmt_fetch

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

/* bind result variables */ 
$stmt->bind_result($name, $code); 

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

/* close statement */ 
$stmt->close(); 
+0

感謝。任何想法如何將它分配給一個變量? – Drew

+0

分配給變量的含義是聲明變量,然後使用bind_result綁定到結果集並調用fetch,變量包含行的值。您應該先閱讀文檔。 –