Saturday, April 16, 2016

Uploading Image File With PHP (Creating Database Class) : Part-02

define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'fileupload');
* Database Class
class Database{
 public $host   = DB_HOST;
 public $user   = DB_USER;
 public $pass   = DB_PASS;
 public $dbname = DB_NAME;

 public $link;
 public $error;

 function __construct(){

 private function connectDB(){
  $this->link = new mysqli($this->host, $this->user, $this->pass, 
  if (!$this->link) {
   $this->error = "Connection fail.".$this->link->connect_error;

 //Insert Data
 public function insert($data){
  $insert_row = $this->link->query($data) or 
  if ($insert_row) {
   return $insert_row;
  } else {
   return false;

 // Select Data
 public function select($data){
  $result = $this->link->query($data) or 
  if ($result->num_rows > 0) {
   return $result;
  } else {
   return false;
Include the below code in index.php
include 'lib/config.php';
include 'lib/Database.php';
$db = new Database();

How to practice tutorials…

  • Make a team with your friends (Member should be 4/5).
  • Start to practice one tutorial series along with them.
  • Don’t try to collect source code. Type the code while watching the tutorial.
  • If you face any problem, post the question in the Forum with the error codes.
  • Share that question Link with your friends or team members to solve quickly.
  • Discuss the problem in the Forum along with others - Video Guidelines.