【发布时间】:2019-01-05 22:46:25
【问题描述】:
当我尝试创建一个类来连接数据库时 我收到了这个错误
致命错误:无法在第 11 行的 C:\xampp\htdocs\project\include\config.php 中重新声明类连接
我创建了一个带有函数 connect with mysqli vars 的类, 但我没有得到没有错误的好结果。
config.php
<?php
if(!isset($_SESSION))
{
session_id("hassan");
session_start();
}
class connect {
var $dbhost="localhost";
var $dbuser="root";
var $dbpass="";
var $dbname="projects";
var $dbport=3306;
var $mycon;
//error_reporting(0);
function contact(){
$con1=mysqli_connect($this->dbhost,$this->dbuser,$this->dbpass,$this->dbname,$this->dbport);
if(!$con1)
include_once "error.html";
mysqli_query($con1,"set names 'utf8'");
if($con1){
include_once dirname(__DIR__) ."/template/title.php";
$this->mycon = $con;
}
return $this->mycon;
}
}
$con= new connect();
$con->contact();
?>
<?php
?>
有什么办法解决吗? 我尝试了很多方法..
【问题讨论】:
-
我们需要知道第 11 行是什么以及哪个文件。您发布的内容不支持该问题/错误。
-
第 11 行类连接 {
-
第 11 行类连接 { @FunkFortyNiner
-
您包含该文件两次。不要。
-
@ÁlvaroGonzález 它仍然给我一个错误