Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Klasy w php.
IdeaProgram
post
Post #1





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 3.03.2016

Ostrzeżenie: (0%)
-----


Witam, posiadam dwie klasy, DB i Player, w player w konstrukcie zrobilem laczenie z DB. W funkcji getPlayer w Player mam dane o uzytkowniku np. $this->id = $array['id']; teraz gdy zrobilem nowa funkcje pod funkcja getPlayer w tej samej klasie gdy odwoluje sie do id czyli $this->id nie pobiera mi juz tego id. Czy musze robic jakas specjalna publiczna funkcje lub cos innego abym mogl z tego korzystac?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
IdeaProgram
post
Post #2





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 3.03.2016

Ostrzeżenie: (0%)
-----


Uzupełniłem ręcznie zapytanie i mam problem z bazą.

  1. class DB {
  2.  
  3. public $db = null;
  4.  
  5. public function __construct() {
  6.  
  7. include_once "system/config.php";
  8.  
  9. $this->db = new mysqli(DB_SERVER, DB_USER, DB_PASS, DBNAME);
  10.  
  11. if ($this->db->connect_errno) {
  12.  
  13. echo "Error MySQLi: (". $this->db->connect_errno . ") " . $this->db->connect_error;
  14.  
  15. exit();
  16. }
  17. }
  18.  
  19. public function connect()
  20. {
  21. $this->db = new mysqli(DB_SERVER, DB_USER, DB_PASS, DBNAME);
  22. return $this->db;
  23. }
  24.  
  25. public function query($query)
  26. {
  27.  
  28.  
  29. //
  30. }
  31. }
  32.  
  33. class Player
  34. {
  35. public $player;
  36.  
  37. public function __construct()
  38. {
  39. mb_internal_encoding( 'UTF-8' );
  40. mb_regex_encoding( 'UTF-8' );
  41. mysqli_report( MYSQLI_REPORT_STRICT );
  42.  
  43. $this->db = new DB();
  44. }
  45.  
  46. public function getPlayer($array)
  47. {
  48. $object = array();
  49.  
  50. $this->id = $array['id'];
  51.  
  52. $user = $this->db->query('SELECT * FROM `user` WHERE `id` = 1');
  53.  
  54. foreach($user as $key => $value)
  55. {
  56. array_push($object, $value);
  57. }
  58.  
  59. debug($object);
  60.  
  61. }
  62.  
  63. public function getGuild()
  64. {
  65. /* */
  66. }
  67.  
  68. }


Bład:

  1. Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\_class.php on line 59
  2. (
  3. )


Coś skopałem chyba z bazą.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 15.10.2025 - 07:52