This file is names as public-function.php
function getPublishedPosts() {
// use global $conn object in function
global $conn;
$sql = "SELECT * FROM posts WHERE published=true";
$result = mysqli_query($conn, $sql);
// fetch all posts as an associative array called $posts
$posts = mysqli_fetch_all($result, MYSQLI_ASSOC);
return $posts;
}
and while calling data to index.php with command
<?php require_once( ROOT_PATH . '/includes/public_functions.php') ?>
<!-- Retrieve all posts from database -->
<?php $posts = getPublishedPosts(); ?>
Its showing the error as:
Fatal error: Uncaught Error: Call to undefined function mysqli_fetch_all() in C:\MAMP\htdocs\complete-blog-php\includes\public_functions.php:12 Stack trace: #0 C:\MAMP\htdocs\complete-blog-php\index.php(10): getPublishedPosts() #1 {main} thrown in C:\MAMP\htdocs\complete-blog-php\includes\public_functions.php on line 12