mysqli_fetch_all在调用数据到其他文件时不起作用

时间:2018-11-01 06:52:47

标签: php html mysql database

此文件的名称为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;
}

并在使用命令将数据调用到index.php时

<?php require_once( ROOT_PATH . '/includes/public_functions.php') ?>

<!-- Retrieve all posts from database  -->
<?php $posts = getPublishedPosts(); ?>

它显示错误为:

  

致命错误:未捕获错误:调用C:\ MAMP \ htdocs \ complete-blog-php \ includes \ public_functions.php:12中未定义的函数mysqli_fetch_all()堆栈跟踪:#0 C:\ MAMP \ htdocs \ complete -blog-php \ index.php(10):getPublishedPosts()#1 {main}在第12行的C:\ MAMP \ htdocs \ complete-blog-php \ includes \ public_functions.php中抛出

0 个答案:

没有答案