User.php 892 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace Core;
  3. class User{
  4. protected $db;
  5. public function __construct()
  6. {
  7. $this->db = new \Core\Databases\Mysqli();
  8. $this->db->connect('39.100.75.63:33060', 'root', 'mysql57-2020!d', 'prictice');
  9. }
  10. public function getUserById($id)
  11. {
  12. $res = $this->db->query("select * from test where id=".$id)->fetch_all(MYSQLI_ASSOC)[0];
  13. $this->id = $res['id'];
  14. $this->name = $res['name'];
  15. $this->mobile = $res['mobile'];
  16. $this->regtime = $res['regtime'];
  17. return $this;
  18. }
  19. public function save()
  20. {
  21. $sql = "update test set name = '{$this->name}',mobile = '{$this->mobile}',regtime = '{$this->regtime}' where id = '{$this->id}'";
  22. $this->db->query($sql);
  23. }
  24. public function getIds()
  25. {
  26. return $this->db->query("select id from test")->fetch_all(MYSQLI_ASSOC);
  27. }
  28. }