Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][OOP] Klasa do łączenia się z bazą danych - czy dobrze jest skonstruowana?
Dominator
post
Post #1





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

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


Witajcie
Dawno nic w php nie robiłem, więc tak dla przypomnienia zrobiłem sobie klasę, która łączy się z bazą danych. Mam takie pytanie - czy ja dobrze to zrobiłem? Co ewentualnie proponujecie zmienić?
Ogólnie to jestem w trakcie przesiadki na OOP, więc nie krzyczcie biggrin.gif

  1. <?php
  2.  
  3. Class UserInterface
  4. {
  5. public function SetDBData($_server, $_port, $_username, $_password, $_database);
  6. {
  7. $this->server = $_server;
  8. $this->port = $_port;
  9. $this->user = $_username;
  10. $this->password = $_password;
  11. $this->database = $_database;
  12. }
  13. public function DBConnect()
  14. {
  15. Try
  16. {
  17. $pdo = new PDO('mysql:host='.$this->server.';dbname='.$this->database.';port='.$this->port, $this->username, $this->password );
  18. }
  19. catch(PDOException $e)
  20. {
  21. return "Error! Code ->".$e;
  22. }
  23. }
  24. }
  25.  
  26. $_UI = new UserInterface();
  27. $this->SetDBData("","","","");
  28. $this->DBConnect();
  29.  
  30. ?>
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: 20.08.2025 - 19:05