I am still learning PHP OOP and english too.
I do not know how I return result from database. I wrote method, which returns results:
class Serial extends DbUser {
public $history, $sn, $added, $numrows;
function __construct() {
parent::__construct('localhost', 'michal', '', 'test');
}
function historyProduct($sn) {
$result = $this->history = $this->conn->prepare("SELECT * FROM `products` WHERE sn = ?");
$result = $this->history->bind_param('s', $sn);
$result = $this->history->execute();
$result = $this->history->get_result();
return $result;
while ($row = mysqli_fetch_array($result)) {
$this->sn = $row['sn'];
$this->added = $row['added'];
}
$this->numrows = mysqli_num_rows($result);
}
function __toString() {
return (string) $this->numrows;
}
}
$sn = $_GET['sn'];
$history = new Serial();
$history->historyProduct($sn);
printf($history);
echo $history->added;
But this method does not display anything.
I have tried with this:
return values from class php oop
What I am doing wrong?
Michał.
return $result;in your method pretty much ensures that nothing will be set for theaddedand thenumrowsproperties of the class;