I am new to php. I encountered the following errors.
Warning: require_once(/dbtest/db_connect.php): failed to open stream: No such file or directory in C:\xampp\htdocs\dbtest\connect.php on line 2
Fatal error: require_once(): Failed opening required 'dbtest/db_connect.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\dbtest\connect.php on line 2
I am very sure I have db_connect.php file inside my dbtest folder. Please help
I
config.php
<?php
define ( 'DB_HOST', 'localhost' );
define ( 'DB_USER', 'root' );
define ( 'DB_PASSWORD' );
define ( 'DB_NAME', 'mydb' );
?>
db_connect.php
<?php
/**
* A class file to connect to database
*/
class DB_CONNECT {
// constructor
function __construct() {
// connecting to database
$this->connect();
}
// destructor
function __destruct() {
// closing db connection
$this->close();
}
/**
* Function to connect with database
*/
function connect() {
require_once '/dbtest/config.php';
$con = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else {
echo 'Connection Successful';
}
}
/**
* Function to close db connection
*/
function close() {
// closing db connection
mysql_close();
}
}
?>
connect.php
<?php
require_once '/dbtest/db_connect.php';
$db = new DB_CONNECT();
$db->connect();
?>