Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Przekazanie zmiennej z jednej funkcji statycznej do drugiej wewnątrz klasy(?), Łączenie i rozłączanie z bazą danych
Leopard
post
Post #1





Grupa: Zarejestrowani
Postów: 20
Pomógł: 2
Dołączył: 20.07.2008

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


Mam taką klasę:

  1. <?php
  2. class DatabaseManager
  3. {
  4.    private $connection;
  5.    public $registeredUsersNames = array();
  6.    public $registeredUsersEmailes = array();
  7.    
  8.    private static function _getConnection()
  9.    {
  10.        $connection = mysql_connect('localhost', 'root', '')or die(mysql_error());
  11.        mysql_select_db('news')or die(mysql_error());
  12.    }
  13.    
  14.    private static function _closeConnection()
  15.    {
  16.        mysql_close($connection);
  17.        unset($connection);
  18.    }
  19.    
  20.    public static function getRegisteredUsersData()
  21.    {
  22.        self::_getConnection();
  23.        $query = "SELECT name, email FROM users";
  24.        $result = mysql_query($query)or die(mysql_error());
  25.        while($row = mysql_fetch_assoc($result)) {
  26.            $registeredUsersNames[] = $row['name'];
  27.            $registeredUsersEmailes[] = $row['email'];
  28.        }
  29.        self::_closeConnection();
  30.        $data = array_combine($registeredUsersNames, $registeredUsersEmailes);
  31.        return $data;
  32.    }
  33.    
  34.    public static function registerNewUser($name, $pass, $email)
  35.    {
  36.        
  37.    }
  38. }
  39. ?>


Nie wiem co zrobić żeby przekazać zmienną $connection z metody _getConnection do _closeConnection?
$connection w _closeConnection nie istnieje więc nie mogę zamknąć połączenia.

Wszelkie krytyczne uwagi na temat klasy mile widziane (IMG:http://forum.php.pl/style_emoticons/default/guitar.gif)
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 - 06:13