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; }