Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Session_handler - brak połączenia z baza
tabbi
post
Post #1





Grupa: Zarejestrowani
Postów: 150
Pomógł: 3
Dołączył: 30.10.2010

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


Witam,

po mału tworze session handler jednak mam problem bo nie chce on mi się łączyć z bazą danych mysql.

  1. class Session
  2. {
  3.  
  4. //baza local / dane
  5. var $_dbh;
  6. var $_db = array();
  7.  
  8. //sesja
  9. var $_sess_name=NULL;
  10.  
  11. var $_sess_id=NULL;
  12.  
  13. var $_sess_opt=array();
  14.  
  15. var $_SESS_LIFE;
  16.  
  17. function __construct($_param = array()){
  18.  
  19. if (!is_array($_param)) {
  20. $this->_handleErrors(STOP);
  21. } else {
  22.  
  23. $this->_db['db_host'] = $_param['db_host'];
  24. $this->_db['db_name'] = $_param['db_name'];
  25. $this->_db['db_user'] = $_param['db_user'];
  26. $this->_db['db_pass'] = $_param['db_pass'];
  27. $this->_db['db_persistent']=NULL;
  28.  
  29. //tworzenie session
  30. session_set_save_handler(array(&$this, '_open'),
  31. array(&$this, '_close'),
  32. array(&$this, '_read'),
  33. array(&$this, '_write'),
  34. array(&$this, '_destroy'),
  35. array(&$this, '_gc')
  36. );
  37. }
  38. }
  39.  
  40.  
  41. function _open($sess_savepath, $sess_name)
  42. {
  43. $this->_sess_name = $sess_name;
  44.  
  45.  
  46. if (!is_resource($this->_dbh)) {
  47. if ($this->_db['db_persistent']) {
  48. $this->_dbh = @mysql_pconnect($this->_db['db_host'],
  49. $this->_db['db_user'],
  50. $this->_db['db_pass']
  51. );
  52. } else {
  53. $this->_dbh = @mysql_connect ($this->_db['db_host'],
  54. $this->_db['db_user'],
  55. $this->_db['db_pass']
  56. );
  57. }
  58. }
  59.  
  60. if (!$this->_dbh)
  61.  
  62. // Problem z połączeniem
  63. $this->_handleErrors(STOP);
  64. else {
  65. $_db_select = @mysql_select_db($this->_db['db_name'], $this->_dbh);
  66.  
  67. if (!$_db_select)
  68. // Problem z połączniem z db_name
  69. $this->_handleErrors(STOP);
  70. }
  71.  
  72. $this->_sess_name = session_name();
  73. $this->_sess_id = session_id();
  74. return true;
  75. }


Inicjacja sesji:

  1.  
  2. require_once("include/class_session.php");
  3.  
  4. $sess_param = array();
  5.  
  6. $sess_param['db_host']="locahost";
  7. $sess_param['db_name']="test2";
  8. $sess_param['db_user']="szpital";
  9. $sess_param['db_pass']="asdasd";
  10. $session = new Session(&$sess_param);


Powinny wyskakiwać błędy że nie mogło się połączyć z baza danych a jednak nie wyskakuje. Prosze o wyrozumiałość
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 - 20:35