Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Problem z klasami
Matimor
post
Post #1





Grupa: Zarejestrowani
Postów: 287
Pomógł: 10
Dołączył: 22.08.2009

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


Witajcie
Mam otóż taki problem, mam zrobioną klasę kod niżej, i teraz po zrobieniu takiej formy jaka jest wywołuje mi błąd, że connect -> query nie istnieje.

  1. class Config
  2. {
  3. var $connect;
  4.  
  5. function cos()
  6. {
  7. $query = $this -> connect -> query();
  8. }
  9. }


Normalnie wyglądało by tak:
  1. class Config
  2. {
  3. function cos()
  4. {
  5. global $connect;
  6. $query = $connect -> query();
  7. }
  8. }



Druga forma działa lecz chcę używać pierwszej, zwracany błąd:
Kod
Fatal error: Call to a member function query() on a non-object in



Pozdrawiam i prosze o pomoc.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Matimor
post
Post #2





Grupa: Zarejestrowani
Postów: 287
Pomógł: 10
Dołączył: 22.08.2009

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


class.connect.php
  1. <?php
  2.  
  3. @require_once("db_mysqli.php");
  4. require_once("settings.php");
  5. $connect = @new mysqli($settings['MySQLHost'], $settings['MySQLUser'], $settings['MySQLPass'], $settings['MySQLDatabase']);
  6. require_once("class.config.php");
  7. ?>


class.config.php
  1. <?php
  2. class Config
  3. {
  4. var $connect;
  5. var $settings = array()
  6.  
  7. function load($name)
  8. {
  9. if($settings[$name] != null)
  10. {
  11. return $settings[$name];
  12. }
  13. else
  14. {
  15. $result = $this -> connect -> query("SELECT `value` FROM `config` WHERE `setting`='{$name}'");
  16. if($result == true)
  17. {
  18. if(($row = $result -> fetch_assoc() != null)
  19. {
  20. return $row[$name];
  21. }
  22. }
  23. }
  24. }
  25. }
  26. ?>
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: 5.10.2025 - 11:15