Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Fatal error: Exception thrown without a stack frame in Unknown on line 0, Problem z unique
Jarod
post
Post #1





Grupa: Zarejestrowani
Postów: 1 190
Pomógł: 27
Dołączył: 23.04.2005

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


Mam taki kod (niedokończony ale odczytuje dane z bazy i zapisuje).
  1. <?php
  2.  
  3. require_once('Core/Cube/Session/SessionHandler.interface.php');
  4. require_once('Core/Cube/Session/SessionException.class.php');
  5. require_once('Core/Cube/Database/' . Config::$DbType . '/' . Config::$DbType . '.class.php');
  6.  
  7. class CubeSession implements SessionHandler
  8. {
  9. private $sSessionValues = null;
  10. private $sAddressIp = null;
  11. private $oConnection = null;
  12. private $sLogin = null;
  13.  
  14. public function __construct($oRegistry, $sConnectionName)
  15. {
  16. $this->oConnection = $oRegistry->get($sConnectionName);
  17.  
  18. session_set_save_handler(array(&$this, 'open'), array(&$this, 'close'), array(&$this, 'read'), array(&$this, 'write'), array(&$this, 'destroy'), array(&$this, 'gc'));
  19.  
  20. $this->sAddressIp = $_SERVER['REMOTE_ADDR'];
  21. if (isset($_SESSION['Login'])) $this->sLogin = $_SESSION['Login'];
  22. }
  23.  
  24. public function open($sSessionSavePath, $sSessionName)
  25. {
  26. return true;
  27. }
  28.  
  29. public function close()
  30. {
  31. $this->gc(Config::$SessionMaxLifeTime);
  32. return true;
  33. }
  34.  
  35. public function read($sSessionId)
  36. {
  37. $this->oConnection->query('SELECT sessions_values FROM sessions WHERE sessions_identifier = '' . $sSessionId . ''');
  38. $this->sSessionValues = $this->oConnection->fetchOne();
  39.  
  40. return $this->sSessionValues;
  41. }
  42.  
  43.  
  44. public function write($sSessionId, $aSessionValues)
  45. {
  46. $aInsert = array('sessions_identifier'=>session_id(), 'sessions_time_start'=>'21:15',
  47. 'sessions_last_time' => '21:16', 'sessions_values'=>'serialize','login'=>'dupa', 'address_ip'=>$this->sAddressIp );
  48. @$this->oConnection->insert('sessions', $aInsert);
  49.  
  50.  
  51. echo '<br/>Metoda write() została wywołana<br/>';
  52. }
  53.  
  54. public function destroy($sSessionId){}
  55.  
  56. public function gc($iSessionLifeTime)
  57. {
  58. echo 'Zniszczone';
  59. }
  60.  
  61. }
  62.  
  63.  
  64. ?>


Błąd, który podałem w temacie pojawia się gdy tabela sessions wygląda tak:
  1. CREATE TABLE sessions
  2. (
  3. sessions_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  4. sessions_identifier VARCHAR(32) NOT NULL,
  5. sessions_time_start TIME NOT NULL,
  6. sessions_last_time TIME NOT NULL,
  7. sessions_values TEXT NOT NULL,
  8. login VARCHAR(20),
  9. address_ip VARCHAR(15),
  10. UNIQUE(sessions_identifier)
  11. ) ENGINE = InnoDB DEFAULT CHARSET=utf8;


Jeśli usunę UNIQUE(sessions_identifier) z tabeli to błąd się nie pojawia. Można to obejść sprawdzając czy wpis o podanym numerze sesji istnieje. Jeśli nie to wykonujemy insert a jeśli istnieje to update.
Problem w tym, że zawsze sprawdzałem to poprzez mysql_affected_rows(). Niestety w tym wypadku to nic nie daje i błąd się pojawia. Mógłbym wykonywać selecta i sprawdzać czy został zwrócony wynik (jeśli tak to wpis już istnieje) ale chciałbym uniknąć zbędnego zapytania do bazy..

Macie jakiś pomysł?
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: 23.08.2025 - 08:59