Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php][mysql] Połączenie z bazą, działanie funkcji
Wolfie
post
Post #1





Grupa: Zarejestrowani
Postów: 686
Pomógł: 0
Dołączył: 10.11.2008
Skąd: Łódź

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


Witam,

Przerabiam ksiazke dotyczaca programowania obiektowego i jest tam klasa sluząca do połączenia z bazą :

  1. <?php
  2.  
  3.    class MySqlConnect {
  4.        private $connection;
  5.        private static $instances = 0;
  6.        
  7.        public function __construct($hostname, $username, $password) {
  8.            if(MySqlConnect::$instances == 0) {
  9.                $this->connection = mysql_connect($hostname, $username, $password) or die (mysql_error().' Błąd nr: '.mysql_errno());
  10.                MySqlConnect::$instances = 1;
  11.            } else {
  12.                $msg = 'Zamykam egzemplarz klasy'.MySqlConnect.'';
  13.                die($msg);
  14.            }
  15.        }
  16.        
  17.        public function close() {
  18.            MySqlConnect::$instances = 0;
  19.            if(isset($this->connection)) {
  20.                mysql_close($this->connection);
  21.                unset($this->connection);
  22.            }
  23.        }
  24.        
  25.        public function createResultSet($strSQL, $databasename) {
  26.            $rs = new MySqlResultSet($strSQL, $databasename, $this->connection);
  27.            return $rs;
  28.        }
  29.        
  30.        function getConnection() {
  31.            $this->connection;
  32.        }
  33.        
  34.        function getVersionNumber() {
  35.            //mysql_get_server_info
  36.            return mysql_get_server_info();
  37.        }
  38.        
  39.        function __destruct() {
  40.            $this->close();
  41.        }
  42.    }
  43. ?>


W klasie tej istnieje funkcja :

  1. <?php
  2. function getConnection() {
  3.              $this->connection;
  4.          }
  5. ?>


I zastanawiam się czy ta funkcja nie powinna zwracać wartości ?

  1. <?php
  2. function getConnection() {
  3.              return $this->connection;
  4.          }
  5. ?>


I jesli sie myle to jak w takim razie wykorzystac taka funkcje ktora nic nie zwraca ? Na jakiej zasadzie taka funkcja dziala ?
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: 21.08.2025 - 08:51