Skip to content

Instantly share code, notes, and snippets.

@teramuza
Created April 30, 2018 13:33
Show Gist options
  • Save teramuza/69f28c1c88ab34ada09b78c7f0eb71a1 to your computer and use it in GitHub Desktop.
Save teramuza/69f28c1c88ab34ada09b78c7f0eb71a1 to your computer and use it in GitHub Desktop.
OOP PHP
<?php
class database
{
var $dbhost = 'localhost';
var $dbuser = 'raja';
var $dbpass = 'min1011';
var $dbname = 'db_oop1';
function __construct()
{
$connect = new mysqli($this->dbhost, $this->dbuser, $this->pass,$this->dbname);
if($connect->connect_error){ die('DATABASE ERROR : '.$connect->connect_error);}
}
function getData($table, $select = '*', $where = '')
{
if(!$where = ''){ $getWhere = 'where '.$where;}else{ $getWhere = '';}
$get = mysqli_query('select '.$select.' from '.$table. ' '.$getWhere);
while($d = mysqli_fetch_array($get)){
$data[] = $d;
}
return $data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment