【发布时间】:2019-02-22 17:43:57
【问题描述】:
标题说明了一切。我也尝试使用 mysqli_fetch_assoc 但它也返回 null !与数据库的连接不是问题,因为它已经完成并且“用户”拥有所有权限。请看一下代码,如果可以的话,请帮助我...
<?php
require 'connect.php';
$sql = mysqli_query("select * from 'info' order by id desc");
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>List</title>
<link rel="stylesheet" href="member_list.css">
</head>
<body>
<h1>Users</h1>
<table class="rwd-table">
<tr>
<th>Number</th>
<th>Name</th>
<th>Family</th>
</tr>
<?php
while($row = mysqli_fetch_assoc($sql)):
$i= 1;
?>
<tr>
<td data-th="Number"><?php echo $i; ?></td>
<td data-th="Name"><?php echo $row['name']; ?></td>
<td data-th="Family"><?php echo $row['family']; ?></td>
</tr>
<?php
$i++;
endwhile; ?>
</table>
</body>
</html>
这里是连接文件:
<?php
/**
* Created by PhpStorm.
* User: reza
* Date: 2019-02-22
* Time: 18:57
*/
session_start();
ob_start();
$host = "localhost";
$username = "db2u";
$password = "1234";
$database = "db2";
$conn = mysqli_connect("$host" , "$username" , "$password" , "$database");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
【问题讨论】:
-
是throwing an error吗?另外(我的 php 有点生疏)
mysqli_query()中的第一个参数不应该是 `mysqli_connect` 对象吗?我认为这里丢失已久的错误会表明,如果是这样的话。
标签: php arrays database mysqli fetch