1. OOP Simple Database Connection

  1. At first you have to create database name, in phpmyadmin.
  2. You have to put a php file in htdocs.
<?php

class fresh{
    public $connect;
    public function __construct($host,$user,$pass,$db) {
        $this->connect = mysqli_connect($host, $user, $pass, $db);
        if(mysqli_connect_errno()){
            die ("your connection fail");
        }
        else{
            echo "Connection success";
        }
    }
    
}

$obj= new fresh("localhost","root","","fresh");

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s