2014-01-07 24 views
-1

與數據庫的連接正在工作。 display_all()是問題所在。它不顯示結果,因爲它表明有人可以幫助查明問題可能出在哪裏。?我對PHP非常陌生,我剛剛在這個上花了幾個小時,但不知道問題出在哪裏。我試圖顯示來自數據庫的結果。我想如果有人能夠確定問題或事實在程序中的確切位置。從數據庫中選擇結果不起作用。我正在使用準備語句

<?php 

class connect_dbase{ 

public $mysqli; 

    public function connection($host="localhost",$user="root",$password="london",$db_name="users") 
    { 
    $this->mysqli=new mysqli($host,$user,$password,$db_name); 
    if ($this->mysqli->connect_error) { 
     die('Connect Error: ' . $this->mysqli->connect_error); 
    } 
    else 
    { 
     echo " Database connection successful"; 
    } 
    } 

    public function display_all($id)  
    { 
    if($stmt = $this->mysqli->prepare("SELECT * FROM user WHERE id =?")) 
    { 
     /* bind parameters for markers */ 
     $stmt->bind_param('i',$id); 

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

     if($stmt->num_row() >0) 
     { 
     echo 'Total results: ' . $resultrol->num_rows; 
     $result = $stmt->get_result(); 
     while ($row = $result->fetch_assoc()) { 
      // do something with $row 
      echo $row['name']; 
     } 
     } 
     else 
     { 
     echo "no result found"; 
     } 
    } 
    else 
    { 
     echo "cant prepare result"; 
    }  
    } 
} 
$connect_dbase=new connect_dbase(); 

$connect_dbase->connection(); 
$connect_dbase->display_all(2); 
?> 
+0

好的。如果我刪除該行 \t echo'Total results:'。 $ resultrol-> NUM_ROWS ;.它仍然無法工作。 – user3157350

+0

如果($ stmt-> num_row()> 0)應該是if($ stmt-> num_rows()> 0) –

+0

您的表中有'name'列嗎?你看到了什麼確切的錯誤? –

回答

1
echo 'Total results: ' . $resultrol->num_rows; 
    $result = $stmt->get_result(); 

不宜$resultrol被undefinded?

+0

是的,它會,但不會阻止PHP繼續。 – frosty11x

相關問題