【发布时间】:2017-09-11 10:39:48
【问题描述】:
我正在使用此代码进行连接:
require_once('db_credentials.php');
function db_connect() {
$connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
return $connection;
}
function db_disconnect($connection) {
if(isset($connection)) {
mysqli_close($connection);
}
}
?>
这是我的 db_credentials.php 文件:
<?php
define("DB_SERVER", "localhost");
define("DB_USER", "");
define("DB_PASS", "");
define("DB_NAME", "globe_bank");
我使用一个简单的 assoc 语句来显示我的名为 subject 的表,但我在网站上根本没有显示。
我想我可能在我的 db_credentials 中写错了信息
我创建了一个名为 hej 的用户,密码为 123,并且该用户已被授予所有访问权限。
这是我的索引文件,我试图在其中显示名为主题的表:
<?php require_once('../../../private/initialize.php'); ?>
<?php
$subject_set = find_all_subjects();
?>
<?php $page_title = 'Subjects'; ?>
<?php include(SHARED_PATH . '/staff_header.php'); ?>
<div id="content">
<div class="subjects listing">
<h1>Subjects</h1>
<div class="actions">
<a class="action" href="<?php echo url_for('/staff/subjects/new.php'); ?>">Create New Subject</a>
</div>
<table class="list">
<tr>
<th>ID</th>
<th>Position</th>
<th>Visible</th>
<th>Name</th>
<th> </th>
<th> </th>
<th> </th>
</tr>
<?php while($subject = mysqli_fetch_assoc($subject_set)) { ?>
<tr>
<td><?php echo h($subject['id']); ?></td>
<td><?php echo h($subject['position']); ?></td>
<td><?php echo $subject['visible'] == 1 ? 'true' : 'false'; ?></td>
<td><?php echo h($subject['menu_name']); ?></td>
<td><a class="action" href="<?php echo url_for('/staff/subjects/show.php?id=' . h(u($subject['id']))); ?>">View</a></td>
<td><a class="action" href="<?php echo url_for('/staff/subjects/edit.php?id=' . h(u($subject['id']))); ?>">Edit</a></td>
<td><a class="action" href="">Delete</a></td>
</tr>
<?php } ?>
</table>
<?php
mysqli_free_result($subject_set);
?>
</div>
</div>
<?php include(SHARED_PATH . '/staff_footer.php'); ?>
【问题讨论】:
-
我想我可能在我的 db_credentials 中写了错误的信息 - 考虑输入正确的凭据或至少在您发布问题之前确认您的怀疑,以便我们更轻松地发布问题?
-
嗯,我使用的凭据是我认为正确的凭据,但由于我没有收到任何输入,我怀疑我可能误解了要使用的正确凭据是什么。 (这就是为什么我包括了截图和用户信息,以防我误解了)