There is such a code:
<?php $title='Post'; $back="index.php"; $logotext= "Post"; $home= "../index.php"; require "header.php"; function get_post_by_id($id) { //Здесь я создал функцию которая получает статью по ее id. global $db; $posts = $db->query("SELECT * FROM posts WHERE id = $id"); foreach ($posts as $post) { return $post; } } ?> <?php $post = get_post_by_id($_GET['id']); ?> And it gives the error: Fatal error: Uncaught Error: Call to a member function query () fullPost.php (20): get_post_by_id (NULL) # 1 {main} thrown in C: \ OSPanel \ domains \ rus \ fullPost.php on line 12
12 line is a line: $posts = $db->query("SELECT * FROM posts WHERE id = $id");
Please help ... Thanks in advance.
$dbat the time of calling thequery. - Yegor Banin