我知道有人问过类似的问题 . 但是,我找到的解决方案都无法解决我的问题 .

我正在使用Avada WordPress主题 . 我为表列表创建了一个自定义页面,要求我连接到数据库以查看元素 . 错误陈述是

致命错误:无法在第49行的/home/public_html/wp-content/themes/Avada/krtcsearcher.php中重新声明类用户

  • 尽管出现错误消息,该函数仍然可以正常工作,因为它显示来自数据库的消息 .

  • 使用localhost-XAMPP(没有wordpress php代码)时该文件运行良好

  • 我在类上尝试过require_once或if(!class_exist)但是没有用 .

Krtcsearcher.php 错误部分看起来像那样

<?php
// Template Name: krtcsearcher
?>


<?php get_header(); ?>

<div id="content" <?php Avada()->layout->add_class( 'content_class' ); ?> <?php Avada()->layout->add_style( 'content_style' ); ?>>
  <?php while ( have_posts() ) : the_post(); ?>

    <?php $page_id = get_the_ID(); ?>
    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
      <?php echo avada_render_rich_snippets_for_pages(); ?>
      <?php echo avada_featured_images_for_pages(); ?>


    <?php


    require_once '/home/public_html/wp-content/themes/Avada/config/connection.php';



     if(!class_exists('DB_Connection')){

      class DB_Connection {


    private $connect;
    function __construct() {
      $this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME)
      or die("Could not connect to database");

    }

    public function getConnection()
    {
      return $this->connect;
    }
      }
    }


    class Users {
        private $db;
        private $connection;

        function __construct() {
          $this -> db = new DB_Connection();
          $this -> connection = $this->db->getConnection();
            //echo "Database Connection Successful!";


        }


        function secinfo($test) {


          $sql = 'Select infoc FROM informations;


          $result = mysqli_query($this->connection, $sql);

          //$row = $result->fetch_assoc(); //get first row of the list
          //while ($row = $result->fetch_assoc()) {
            while ($row = $result->fetch_row()) {
            echo $row[0];


          }
            mysqli_close($this->connection);

          }

       } 

    ?>

新图片*

一切正常,但下面显示的错误消息 .
Web Domain

来自Localhost-XAMPP
XAMMP-Localhost