2016-02-19 124 views
1
public function upload() { 

    try { 
     $database_connect = new DatabaseConnect(); 
     $connection = $database_connect->getConnection(); 

     $this->populate_database($connection); //line 43 
     $connection->close(); 

     return true; 

    } catch (Exception $exp) { 
     echo $exp->getMessage(); 
     return false; 

    } 

} 

private function populate_database(mysqli $connection){ 
    $query = "insert into bases (img_url) values ($this->image_name)"; 
    $result = $connection->query($query); 

    if (!$result) die($connection->error); 

    if (!$this->update_linked_table($connection)) { 
     echo "linked table not updated"; 
    } 
} 

我打電話民辦非靜態方法那麼爲什麼會出現這個錯誤:錯誤調用非靜態方法

Fatal error: Using $this when not in object context in /var/www/html/CocExplore/html5BoilerPlate/php/LocalImage.php on line 43

+0

提供類DatabaseConnect的代碼 – CodeGodie

+0

問題在於如何調用'upload'。顯示調用它的代碼。 – Barmar

+1

對不起,如果這看起來微不足道,但在你的例子中只有29行。你能發佈第43行嗎?... – War10ck

回答

0

呼叫方法非靜態。例如,如果您致電YourClass::upload(),請將其替換爲類似$class = new YourClass(); $class->upload();

+0

你能解釋爲什麼嗎? – 2016-02-19 20:52:29