的config.php
<?php
class DB {
protected $db_name = 'drive';
protected $db_user = 'root';
protected $db_pass = '';
protected $db_host = 'localhost';
public function connect() {
$connection = mysql_connect($this->db_host, $this->db_user, $this->db_pass);
mysql_select_db($this->db_name);
return true;
}
class showClass{
//USER LIST SHOW function
public function showUser($table){
$query=mysql_query("SELECT * FROM $table WHERE type='user'") or die(mysql_error());
$data=NULL;
if(mysql_num_rows($query)>0){
while($rows=mysql_fetch_assoc($query)){
$data[]=$rows;
}
return $data;
}else{
echo '<span class="text-info success">No Account Found.</span>';
exit();
}
}
}
的index.php
<?php
require_once 'conf/config.php';
$db = new DB();
$db->connect();
$obj_show = new showClass();
?>
<html>
<head>
<title>Drive</title>
</head>
<body>
<table class="table table-bordered table-hover" cellpadding="5">
<tr>
<th scope="col"><b>User ID</b></th>
<th scope="col"><b>Name</b></th>
</tr>
<?php
$allData=$obj_show->showUser("user");
foreach($allData as $data){
extract($data);
echo <<<show
<tr>
<td>$id</td>
<td >$username</td>
</tr>
show;
}
?>
</table>
</body>
答案 0 :(得分:2)
正如我在评论中已经说过的那样,在类DB 结束后,您将缺少} 。
答案 1 :(得分:2)
as @Cruel回答你缺少}在课程结束时 DB 尝试改变
class DB {
protected $db_name = 'drive';
protected $db_user = 'root';
protected $db_pass = '';
protected $db_host = 'localhost';
public function connect() {
$connection = mysql_connect($this->db_host, $this->db_user, $this->db_pass);
mysql_select_db($this->db_name);
return true;
}
}
答案 2 :(得分:1)
您输出时显示的语法错误在添加ini_set function
正确的代码如下,您需要在类DB之后添加一个右括号
<?php
class DB {
protected $db_name = 'drive';
protected $db_user = 'root';
protected $db_pass = '';
protected $db_host = 'localhost';
public function connect() {
$connection = mysql_connect($this->db_host, $this->db_user, $this->db_pass);
mysql_select_db($this->db_name);
return true;
}
}// MISSING CLOSING BRACKET
class showClass{
//USER LIST SHOW function
public function showUser($table){
$query=mysql_query("SELECT * FROM $table WHERE type='user'") or die(mysql_error());
$data=NULL;
if(mysql_num_rows($query)>0){
while($rows=mysql_fetch_assoc($query)){
$data[]=$rows;
}
return $data;
}else{
echo '<span class="text-info success">No Account Found.</span>';
exit();
}
}
}