Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z odwołaniem się do funkcji
Dominator
post
Post #1





Grupa: Zarejestrowani
Postów: 565
Pomógł: 15
Dołączył: 11.10.2010

Ostrzeżenie: (20%)
X----


Cześć,
jestem w trakcie przeprojektowania strony, konfiguracji i innych rzeczy i zmagam się z problemem od ponad godziny. A mianowicie mam dwa pliki - DatabaseConnector.php w którym łączę się z bazami danych oraz PlayerPanel.php.
Tak wygląda struktura pierwszego:

  1. class DatabaseConnector
  2. {
  3. public $pdo;
  4. public $pdo2;
  5. public $host = "xxx";
  6. public $port = 1234;
  7. public $username = "xxx";
  8. public $password = "xxx";
  9. public $database = "xxx";
  10. public $database2 = "xxx";
  11.  
  12. public function __construct()
  13. {
  14. $this->connect();
  15. }
  16.  
  17. public function connect()
  18. {
  19. try
  20. {
  21. $this->pdo = new PDO('mysql:host='.$this->host.';dbname='.$this->database.';port='.$this->port, $this->username, $this->password );
  22. $this->pdo2 = new PDO('mysql:host='.$this->host.';dbname='.$this->database2.';port='.$this->port, $this->username, $this->password );
  23. }
  24. catch(PDOException $e)
  25. {
  26. echo 'Połączenie nie mogło zostać utworzone.<br />'.$e->getMessage();
  27. }
  28. }
  29.  
  30. public function __destruct() {
  31. $this->closeConnection();
  32. }
  33.  
  34. public function closeConnection()
  35. {
  36. $this->pdo = null;
  37. $this->pdo2 = null;
  38. }
  39. }
  40.  



PlayerPanel.php

  1. include "DatabaseConnector.php";
  2. class PlayerPanel extends DatabaseConnector
  3. {
  4. public $nick;
  5. public $kills;
  6. public $deaths;
  7. public $kd;
  8. public $guild;
  9.  
  10. public function __construct($id)
  11. {
  12. if($id == null)
  13. {
  14. die("");
  15. exit();
  16. }
  17.  
  18. $this->nick = $id;
  19.  
  20. echo $this->getPlayerInfo($this->nick);
  21. }
  22.  
  23. public function getPlayerKills()
  24. {
  25. return $this->kills;
  26. }
  27.  
  28. public function getPlayerDeaths()
  29. {
  30. return $this->deaths;
  31. }
  32.  
  33. public function getKDRatio()
  34. {
  35. return $this->kd;
  36. }
  37.  
  38. public function getGuild()
  39. {
  40. return $this->guild;
  41. }
  42.  
  43.  
  44. public function getPlayerInfo($tag)
  45. {
  46. $stmt = $this->pdo2 -> prepare("SELECT * FROM `XXXX` WHERE player=:tag");
  47. $stmt -> bindValue(':tag', $tag, PDO::PARAM_STR); // 2
  48. $stmt->execute();
  49.  
  50. $result = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
  51. return $result;
  52. }
  53.  
  54. public function getPlayerGuild($nick)
  55. {
  56. $stmt = $this->pdo2 -> prepare("SELECT * FROM `XXXX` WHERE player=:tag");
  57. $stmt -> bindValue(':tag', $nick, PDO::PARAM_STR); // 2
  58. $stmt->execute();
  59.  
  60. $results=$stmt->fetchAll(PDO::FETCH_ASSOC);
  61. $json=json_encode($results);
  62. return $json;
  63. }
  64.  
  65.  
  66. }


Chcę sobie wyświetlić statystyki gracza metodą echo $this->getPlayerInfo($this->nick);, ale wygląda, że to wcale nie działa.

Próbowałem różnych metod, cały czas mój php twierdzi, że $this->pdo2 nie istnieje... błąd wygląda następująco: Fatal error: Uncaught Error: Call to a member function prepare() on null in .... 54 (pogrubiłem to w kodzie)

Ten post edytował Dominator 10.06.2017, 18:34:24
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 19.08.2025 - 17:52