Hi I just finished reading a beginner book on PHP and I wana start to create my own login.I did not get very far and I got an error that I can;t seem to fix.
I have 3 files
index.php
session_start();
require 'DB_ACCES/connect.php';
if(isset($_POST['submit'])){
$conn = new Mysqli();
}
constants.php
define('DB_HOST', 'localhost');
define('DB_USER' , 'root');
define('DB_PWD' , '');
connect.php
require '../includes/constants.php';
class Mysqli{
private $conn;
function __construct() {
$this->conn = new mysqli(DB_HOST , DB_USER , DB_PWD) or die(mysqli_error());
}
}
When I run index.php I get this error:
Fatal error: Cannot redeclare class Mysqli in D:\Program Files\xampp\htdocs\MyWork\Blog\DB_ACCES\connect.php on line 4
What am I doing wrong here and how can I repair it?
The bug is exactly what the error states.
Mysqli is an existing class that’s part of a very common php shared library
mysqli. You can’t redeclare it.Change your classname to
MyMysqlior something.