I'm still playing around with classes and can't get this one running:
class db_connection {
private $dbc;
public function __construct()
{
$this->dbc = new mysqli(HOST_ONE, USER_ONE, PASS_ONE, DB_ONE);
}
public function getDbc()
{
return $this->dbc;
}
}
class db_query extends db_connection{
private $querystring;
private $result;
function __construct ($table, $field) {
$this->querystring = $query = parent::getDbc()->query("SELECT ".$field." FROM ".$table);
$this->result = $row = $query->fetch_assoc();
}
function get_resultset() {
return $this->result;
}
}
this is how I try to run it:
$db_conn = new db_connection();
$db = $db_conn->getDbc();
$action = new db_query('datenbanken','id');
$result = $action->get_resultset();
var_dump($result);
The connection is established without any problems, but it won't query the database with my class.
I won't to achieve that I can run a query and only have to set
$action = new db_query('datenbanken','id');
this line...
Can someone help me on how I can solve this? Thanks!