Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class db{
- private $db;
- function __construct($host, $db, $user, $password){
- $this->db = mysqli_connect($host, $db, $user, $password);
- }
- function __destruct(){ mysqli_close($this->db); }
- function query($query){
- $result = mysqli_query($this->db, $query) or die("error");
- return $result;
- }
- }
- class data{
- private $db;
- function __construct(){
- if(empty($this->db)) $this->db = new db("127.0.0.1", "user", "password", "db_name");
- }
- function __sleep(){
- // Отключаемся от бд
- $this->db->__destruct();
- return $this;
- }
- // Метод вызывается перед unserialize()
- function __wakeup(){ self::__construct(); }
- function get(){
- $query = "SELECT * FROM tbl_name";
- $db = $this->db->query($query);
- // Предположим что вернулась одна строка
- print_r(mysqli_fetch_row($db));
- }
- }
- $obj1 = new obj();
- session_start();
- $_SESSION['obj'] = serialize($obj1);
- $obj2 = unserialize($_SESSION['obj']);
- // Тут пишет ошибку
- $obj2->get();
Add Comment
Please, Sign In to add comment