【发布时间】:2018-11-13 03:06:49
【问题描述】:
我写了以下代码,数据无法获取。谁能帮帮我。我主要做过程编程,所以我对 oops 没有太多了解。
1.xyzconfig.php
define("HOST", "localhost");
define("USER", "root");
define("PASSWORD", "");
define("DATABASE", "end");
2.dbconnect.php
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();
}
3.function.php
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>";
}
}
}}
4.test.php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
echo user_fetch($mysqli);
【问题讨论】: