如何在不同页面中调用fetch查询函数(PHP)
我已经编写了以下代码,数据无法提取。有人能帮我吗。我主要做程序编程,所以我对oops没有那么多知识 1.xyzconfig.php 2.dbconnect.php 3.function.php如何在不同页面中调用fetch查询函数(PHP),php,function,oop,mysqli,Php,Function,Oop,Mysqli,我已经编写了以下代码,数据无法提取。有人能帮我吗。我主要做程序编程,所以我对oops没有那么多知识 1.xyzconfig.php 2.dbconnect.php 3.function.php functions.php需要包含dbconnect.php而不是xyzconfig.php include_once 'dbconnect.php'; function user_fetch($mysqli) { if($stmt=$mysqli->prepare("SELE
functions.php需要包含dbconnect.php而不是xyzconfig.php
include_once 'dbconnect.php';
function user_fetch($mysqli)
{
if($stmt=$mysqli->prepare("SELECT id, username,email,role FROM members"))
{
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows >= 1)
{
while($row=$stmt->fetch_assoc() )
{
echo "<tr><td>".$row["id"]."</td><td>".$row["username"]." ".$row["email"]." ".$row['role']."</td></tr>";
}
}
}}
使用这两个store_result()绝对没有意义,我这样做了,但仍然没有获取检查您的SQL
include_once 'xyzconfig.php';
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
if($mysqli->connect_error)
{
header("Location: ../error.php?err=Unable to connect to MySQL");
exit();
}
include_once 'xyzconfig.php';
function user_fetch($mysqli)
{
if($stmt=$mysqli->prepare("SELECT id, username,email,role FROM members"))
{
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows == 1)
{
while($row=$stmt->fetch_assoc() )
{
echo "<tr><td>".$row["id"]."</td><td>".$row["username"]." ".$row["email"]." ".$row['role']."</td></tr>";
}
}
}}
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
echo user_fetch($mysqli);
include_once 'dbconnect.php';
function user_fetch($mysqli)
{
if($stmt=$mysqli->prepare("SELECT id, username,email,role FROM members"))
{
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows >= 1)
{
while($row=$stmt->fetch_assoc() )
{
echo "<tr><td>".$row["id"]."</td><td>".$row["username"]." ".$row["email"]." ".$row['role']."</td></tr>";
}
}
}}
include_once 'includes/dbconnect.php';
include_once 'includes/functions.php';
echo user_fetch($mysqli);