dbConnect.php

back


<?php

class dbConnect {

private $host='localhost';

// Hostname of the database server. This can be a domain or an IP address.

private $username='root';

// Database username.

private $password='root';

// Database password.

private $db='oop';

// Database name.

protected $con;

// Database connection variable. 

function __construct(){

// This function will be called automatically when the object of this class is created.

$this->con=new mysqli($this->host,$this->username,$this->password,$this->db);

// The connection variable is set as an object of the readymade mysqli class.
// In OOP, we use this class for database connection and all other sql queries.

if ($this->con->connect_error){

// In case of error, connect_error variable of the object of mysqli class is set.

echo 'Something is wrong';

}

}

}

?>