I have the following table called info:
info_name | info_value
name | Susan
desc | Human
I'm trying to print Susan without knowing that the value is Susan.
The following code works, but I want to know if what I wrote is correct.
I'm open to any improvements.
Config Class:
class Config {
private $hostname = 'localhost';
private $username = 'blah';
private $password = 'blah';
private $database = 'blah';
public function __construct()
{
$this->connection = new mysqli($this->hostname,$this->username,$this->password,$this->database);
if($this->connection->connect_errno)
{
die('Error: ' . $this->database->error);
}
}
public function query($query)
{
return $this->connection->query($query);
}
public function __destruct()
{
$this->connection->close();
}
}
Name Class:
class Name {
protected $name;
public function __construct()
{
$this->db = new Config;
$r = $this->db->query('SELECT info_value FROM info WHERE info_name="name"');
while($row = $r->fetch_row())
{
$this->name = $row['0'];
}
}
public function getName()
{
return $this->name;
}
}
Print Results:
<?php $show_name = new Name(); echo $show_name->getName(); ?>
Thanks for any help!
$this->database->error
will not work. Maybe you meant$this->connection->error
. \$\endgroup\$