There is a database connection class:
class Mydb { protected $db; public function __construct() { try { $this->db = new PDO('mysql:host=localhost;dbname=mydb', 'root', ''); } catch (PDOException $e) { exit($e->getMessage()); } } } And two successor classes: to add data to the database
class AddData extends Mydb { public function addInfo($name, $tel, $email) { $this->db->exec("INSERT INTO users (name, tel, email) VALUES ('$name', '$tel', '$email'"); } } and for getting from the base
class GetData extends Mydb { public function getInfo() { $this->db->query("SELECT * FROM users"); } } The object of the AddData class with its function copes perfectly:
$add = new AddData(); $add->addInfo('Vasya', '(495) 123-45-67', 'vas@ya.ru'); But the object of the class GetData for some reason returns NULL:
$get = new GetData(); $res = $get->getInfo(); var_dump($res); //NULL And if $ this-> db-> query ("SELECT * FROM users"); put in the constructor of the parent class, then everything works. And through the heir class - no.
What is the problem here and how to solve it?
$add->addInfo('Vasya', '(495) 123-45-67', 'vas@ya.ru\'), (\'Запасной аккаунт\', \'\',\'');- vp_arth