Created
May 18, 2019 09:08
-
-
Save pkavoo/41a3bf4a3a6668ee2c3657fdf02fc718 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Class DbConnect | |
class DbConnect | |
{ | |
//Variable to store database link | |
private $con; | |
//Class constructor | |
function __construct() | |
{ | |
} | |
//This method will connect to the database | |
function connect() | |
{ | |
//Including the constants.php file to get the database constants | |
include_once dirname(__FILE__) . '/Constants.php'; | |
//connecting to mysql database | |
$this->con = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
//Checking if any error occured while connecting | |
if (mysqli_connect_errno()) { | |
echo "Failed to connect to MySQL: " . mysqli_connect_error(); | |
} | |
//finally returning the connection link | |
return $this->con; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment