无法声明类DB_con,因为该名称已在使用中

问题描述 投票:-1回答:1

我正在建立一个项目,但无法与数据库建立连接。这是我的配置文件

class DB_con{

    private $localhost = "localhost";
    private $user = "root";
    private $pass = "";
    private $db_name = "dasmahavidya";
    public $conn;

    public function __construct(){

        if(!isset($this->conn)){

            $this->conn = new mysqli($this->localhost,$this->user,$this->pass,$this->db_name);

            if(!$this->conn){
                echo "Cannot connect to the database";
            }
            // else{
            //  echo "Connected to the database";
            // }

        }

        return $this->conn;
    }
}

我的功能部分是

<?php  

include ('backend_admin_config.php');

class Blog_function extends DB_con{

    public function __construct()
    {
        parent::__construct();
    }

    public function login_insert($myusername){

        $sql = "select * from $tb_login_admin where log_admin_email='$myusername'";
        $result = mysqli_query($this->conn,$sql);
        return $result;
    }
} 
?>

[每当我要运行我的代码时,我都会遇到错误无法声明类DB_con,因为该名称已在使用中

php class oop inheritance crud
1个回答
0
投票

谢谢大家,这是因为包含,我使用了include_once,一切正常。...

© www.soinside.com 2019 - 2024. All rights reserved.