Ejemplo n.º 1
0
class database
{
    protected $sql;
    //Property Variable
    function __construct($host, $username, $password, $dbname)
    {
        //Method
        $this->sql = new mysqli($host, $username, $password, $dbname);
    }
    function view($table, $select = "*", $name = "", $con = "", $val = "")
    {
        $where = ($name != "" and $con != "" and $val != "") ? "WHERE {$name} {$con} '{$val}'" : "WHERE 1";
        //die("SELECT {$select} from {$table} {$where}");
        return $this->sql->query("SELECT {$select} from {$table} {$where}")->fetch_all(1);
    }
}
class abc extends database
{
    function __construct($host, $username, $password, $dbname)
    {
        parent::__construct($host, $username, $password, $dbname);
    }
    function login($username, $password)
    {
        return $this->sql->query("select * from user where username = '******' AND password = '******'")->fetch_assoc();
    }
}
//$db = new database("localhost","root","root","helfer1");
$db = new abc("localhost", "root", "root", "helfer1");
$result = $db->view("grupos", "nombre", "id_grupo", "=", "4");
print_r($result);