Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Konstruktor nie spełnia swojej funkcji
Nahalem
post
Post #1





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 30.06.2010

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


Mam swoją klasę i konstruktor ale niestety nie spełnia swjej funkcjonalnośći jak powinien. Powinien inicjować połączenie z bazą, w każdej metodze muszę wprowadzać te linijki kodu. Co robię źle w ciele konstruktora?(IMG:style_emoticons/default/questionmark.gif)

  1. class MySQL_class
  2. {
  3. function __construct()
  4. {
  5. require_once("globals.php");
  6. $this->server = DB_SERVER;
  7. $this->username = DB_USER;
  8. $this->password = DB_PASS;
  9. $this->db_name = DB_NAME;
  10. $this->db_connection = mysql_connect($this->server, $this->username, $this->password) or die("Connection failed. Error: " . mysql_error());
  11. $this->db = mysql_select_db(DB_NAME,$this->db_connection) or die("Database selection failed. Error " . mysql_error());
  12. }
  13.  
  14. function Login()
  15. {
  16. require_once("globals.php");
  17. $this->server = DB_SERVER;
  18. $this->username = DB_USER;
  19. $this->password = DB_PASS;
  20. $this->db_name = DB_NAME;
  21. $this->db_connection = mysql_connect($this->server, $this->username, $this->password) or die("Connection failed. Error: " . mysql_error());
  22. $this->db = mysql_select_db(DB_NAME,$this->db_connection) or die("Database selection failed. Error " . mysql_error());
  23.  
  24. $haslo_crypt=crypt($this->passwd,'bab');
  25. $querry = "SELECT nickname, password FROM gracz WHERE nick='$this->nick' AND passwd='$haslo_crypt'";
  26. $result = mysql_query($querry) or die("Error DB querry. Error: " . mysql_error());
  27. while ($this->row = mysql_fetch_array($result))
  28. {
  29. $this->Set_role($this->row['role']);
  30. $this->Set_nick($this->row['nick']);
  31. $this->Set_password($this->row['passwd']);
  32. $this->counter++;
  33. return true;
  34. }
  35. }
  36. }
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: 24.08.2025 - 21:39