Fatal error: Uncaught Error: Call to a member function query() on null in C:\Program Files\Ampps\www\MCV for nordcurrent\app\models\model_product_list.php:45 Stack trace: #0 C:\Program Files\Ampps\www\MCV for nordcurrent\index.php(5): Card->get_cards() #1 {main} thrown in C:\Program Files\Ampps\www\MCV for nordcurrent\app\models\model_product_list.php on line 45
1 <?php 2 3 /* Card class - proccesses all the infromation displayed in the cards */ 4 5 class Card 6 { 7 private $Database; 8 private $db_table = 'card_table'; 9 10 function __constructor() 11 { 12 global $Database; 13 $this->Database = $Database; 14 } 15 16 //Setting / Getting cards from the database 17 18 //Return and array with card information 19 public function get_cards($id = NULL) 20 { 21 $data = array(); 22 if($id != null) 23 { 24 //get specific card 25 if($stmt = $this->Database->prepare("SELECT id, name FROM " . 26 $this->db_table . " WHERE id = ?" )) 27 { 28 $stmt->bind_param("i", $id); 29 $stmt->execute(); 30 $stmt->store_result(); 31 32 $stmt->bind_result($card_id, $card_name); 33 $stmt->fetch(); 34 35 if($stmt->num_rows > 0) 36 { 37 $data = array('id' => $card_id, 'name' => $card_name); 38 } 39 $stmt->close(); 40 } 41 } 42 else 43 { 44 //get all cards 45 (The 45th line where the error is coming from) 46 if($result = $this->Database->query("SELECT * FROM " . $this->db_table . " 47 ORDER BY name")) 48 { 49 if($result->num_rows > 0) 50 { 51 while($row = $result->fetch_array()) 52 { 53 $data[] = array('id' => $row['id'], 'name' => $row['name']); 54 } 55 } 56 } 57 } 58 return $data; 59 } 60 61 62 }
global
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)