2011-07-05 102 views
2

我有我的代碼錯誤有人可以幫我嗎?mysqli bind_param()致命錯誤

<?php 
    $db = new mysqli("localhost","root","","karmintalender"); 

    $owner_ID = 1; 

    $sql = "SELECT name, kalender_ID FROM kalender WHERE ersteller_ID = ?"; 
    $stmt = $db->prepare($sql); 
    $stmt->bind_param("i", $owner_ID); 
    $stmt->execute(); 
    $stmt->bind_results($name, $kalender_ID); 

    while ($stmt->fetch()) { 
    echo $name . " " . $kalender_ID; 
    } 
?> 

當我打開它顯示該錯誤 「致命錯誤:調用一個成員函數bind_param()G中的非對象:\ XAMPP \ htdocs中\ Karmintalender \ test.php的第8行」

回答

3

這條線上的一個字段不存在,請檢查它們。

$sql = "SELECT name, kalender_ID FROM kalender WHERE ersteller_ID = ?"; 

另外,您應該檢查$ stmt。

$db = new mysqli("localhost","root","","karmintalender"); 

$owner_ID = 1; 

$sql = "SELECT name, kalender_ID FROM kalender WHERE ersteller_ID = ?"; 
$stmt = $db->prepare($sql); 
if($stmt){ 
    $stmt->bind_param("i", $owner_ID); 
    $stmt->execute(); 
    $stmt->bind_results($name, $kalender_ID); 

    while ($stmt->fetch()) { 
     echo $name . " " . $kalender_ID; 
    } 
} 
+0

權領域kalender_ID不存在我現在編輯它還有另外一個錯誤「致命錯誤:調用未定義的方法mysqli_stmt :: bind_results()在G:\ XAMPP \ htdocs中\ Karmintalender \ test.php on line 11「 –

+2

http://php.net/manual/en/mysqli-stmt.bind-result.php檢出文檔。 – Eddie

+0

好吧謝謝了:) –

2

應該stmt- $> bind_result($名稱,$ kalender_ID);

下降的S