我写那朵代码使用MVC致命错误:无法声明类数据库,因为该名称已在使用中
登录系统脚本这是类数据库
<?php
class Database
{
private $host;
private $user;
private $password;
private $database;
function __construct($filename)
{
if (is_file($filename))include $filename;
else throw new Exception("Error!");
$this->host =$host;
$this->user =$user;
$this->password =$password;
$this->database =$database;
$this->connect();
}
//Connect the server
private function connect()
{
$conn=mysqli_connect($this->host, $this->user, $this->password, $this->database);
//Check Connection
if(!$conn)
throw new Exception("Error: not connect to the server");
// Select the database
if(!mysqli_select_db($conn,$this->database))
throw Exception("Error!");
}
//Close dataabase connection
function close()
{
mysqli_close();
}
}
?>
当我打电话的这个代码
<?php
/*
//Site login Controller
try {
include './models/database.php';
$vars= 'include/vars.php';
new database($vars);
}
catch (Exception $exc)
{
echo $exc->getMessage();
}
*/
/////////////////////login code start
if ($_POST)
{
if (isset($_POST['submit']) AND $_POST('submit') == "login") ;
{
$data['email'] = $_POST['email'];
$data1['password'] = $_POST['password'];
try
{
include './models/login.php';
$login = new login($data, $data1);
if($login == TRUE)
{
session_start();
$_SESSION['loggedin']='12545526465';
header('Location:index.php');
}
}
catch (Eception $exc)
{
echo $exc->getMessage();
}
}
}
?>
它给我这个
致命错误:无法声明类数据库,因为这个名字已经在第5行
你不从错误消息中了解什么创建数据库对象一次? – 2016-11-09 10:29:27
你应该改变类'Database'的名称,因为它已经开始使用你的框架! –
我没有使用任何框架 – user3794383