I understand that similar questions have been asked. However, none of the solutions I found can solve my problem.
I am using the Avada WordPress theme. I have created a customized page for a table list that requires me to connect to the database to view elements. The error statement is
Fatal error: Cannot redeclare class Users in /home/public_html/wp-content/themes/Avada/krtcsearcher.php on line 49
- Despite error message, the function still works well as it displays the message from the database.
- The file is working well while using localhost-XAMPP (Without wordpress php code)
- I have tried require_once or if(!class_exist) on the class but does not work.
Krtcsearcher.php The error part looks something like that
<?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);
}
}
?>
NEW Pictures*
Everything is working fine but there is an error message shown below.