I want to make a dynamic select statement that can select whatever table I ask for, same with table columns in my database.
Here is my select class so far:
<?php
class select extends database{
// Instance variables
private $id;
public $table;
public $column;
public $sql;
public $result = array();
// Methods - Behavior
public function selectQuery($table){
global $con;
$sql = $this->sql;
$sql = "SELECT * FROM {$table}";
$result = $this->con->query($sql);
while($row = $result->fetch_object()){
//iterate all columns from the selected table
//and return it someway.
}
}
}
$selectQuery = new select();
Here is my database class
require_once(LIB_PATH.DS."config.php");
class database
{
public $con;
public $result = array();
public function __construct()
{
$this->con = new mysqli(DB_HOST,DB_USERNAME,DB_PASSWORD,DB);
if($this->con->connect_error){
die($this->con->connect_error);
}
}
}
$db = new database();
What I'm doing so far is connecting to my Database with mysqli then I extend my select class from my database class so I can get the connection and then I want to select all from.