Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--DatabaseClass.php---->
- <?php
- require_once('config.php');//calling config.php
- class Database{
- public $connection;//property
- //__construct();
- public function __construct(){
- $this->openDbConnection();
- }
- //method
- public function openDbConnection(){
- $this->connection = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
- if (mysqli_connect_errno()) {
- # code...
- die("Database Connection Failed Badly" . mysqli_error());
- }else{
- echo "DB Connected Successfully.";
- }
- }
- }
- //instance of the class
- $database = new Database();
- //calling the Method
- //$database->openDbConnection();
- /*
- *if we call this Method vis Object than Database will be connected
- *but we will make the connection automcatic.
- *so we will use a __construct() to connect DB Atomatically.
- */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement