I connect to the database at the very beginning of the document. After calling the method where the query is created for the menu items

public $db; public function __construct(){ $db = mysqli_connect(HOST, USER, PASSWORD, DB) or die("Ошибка соединения с базой данных"); } public function menu_array(){ $query = "SELECT id_menu, name_menu FROM menu"; $result = mysqli_query($db, $query) or die("Ошибка запроса к таблице - menu"); $row = array(); for ($i=0; $i < mysql_num_rows($result); $i++) { $row[] = mysql_fetch_array($result, MYSQL_ASSOC); } return $row; } 

    1 answer 1

    Good day!

    Apparently this is a class. And in a class, you should access this variable through $this , i.e. $this->db

    • $ result = mysqli_query ($ this-> db, $ query) or die ("Error query to the table - menu"); Not working - FLWRZ4U
    • Did you fix the reference to the constructor in the variable? should be $this->db = mysqli_connect(... - Alex