Note that there are some explanatory texts on larger screens.

plurals
  1. POdatabase session handler problem
    primarykey
    data
    text
    <p>Hello i'm trying to understand how sessions work and how does <code>session_set_handler()</code> works, so i've started build a class for session handling but i've encountered some problems with the <code>write()</code> function can you please help me solve the problem?</p> <pre><code>&lt;?php class Session extends Model { public $connectionName = 'sessions', $sessionsId, $sessionsData; public function __construct() { parent::__construct(); session_set_save_handler( array($this, 'Open'), array($this, 'Close'), array($this, 'Read'), array($this, 'Write'), array($this, 'Destroy'), array($this, 'Gc')); session_start(); } public function __destruct() { session_write_close(); } public function Open() { return true; } public function Close() { return true; } public function Read($sessionsId) { $this-&gt;stmt = $this-&gt;prepare("SELECT * FROM `sessions` WHERE `id` = :sessionId"); $this-&gt;stmt-&gt;bindParam(":sessionId", $sessionsId); $this-&gt;stmt-&gt;execute(); return $this-&gt;stmt-&gt;fetchAll(); } public function Write($sessionsId, $sessionsData) { $this-&gt;stmt = $this-&gt;prepare("REPLACE INTO `sessions`.`sessions` (`id`, `access`, `data`) VALUES (:sessionId, NOW(), :sessionValue)"); $this-&gt;stmt-&gt;bindParam(":sessionId", $sessionsId); $this-&gt;stmt-&gt;bindParam(":sessionValue", $sessionsData); $this-&gt;stmt-&gt;execute(); } public function Destroy($sessionsId) { $this-&gt;stmt = $this-&gt;prepare("DELETE FROM `sessions`.`sessions` WHERE `id` = :sessionId"); $this-&gt;stmt-&gt;bindParam(":sessionId", $sessionsId); $this-&gt;stmt-&gt;execute(); } public function Gc() { $this-&gt;stmt = $this-&gt;prepare("DELETE FROM `sessions`.`sessions` WHERE `access` &lt; NOW() - INTERVAL 1 HOUR"); $this-&gt;stmt-&gt;execute(); } } </code></pre> <p>now the above code seems to work just fine the only problem is when i write a session in db i get the following insert:</p> <p>dump from mysql</p> <pre><code>CREATE TABLE IF NOT EXISTS `sessions` ( `id` varchar(32) NOT NULL, `access` datetime NOT NULL, `data` text NOT NULL, UNIQUE KEY `id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT INTO `sessions` (`id`, `access`, `data`) VALUES ('lhig71coed8ur81n85iiovje37', '2011-07-25 15:37:57', ''); </code></pre> <p>As you can see the value of the session it's not inserted i only get the session id. on <code>var_dump($sessionsData)</code> i get:</p> <pre><code>"name|s:6:"Bogdan";" </code></pre> <p>and for <code>var_dump($sessionsId)</code> i get:</p> <pre><code>lhig71coed8ur81n85iiovje37 </code></pre> <p>Can you please help? i don't get any errors checked xampp logs setup display errors on error reporting everything i knew even in php.ini still no error anything used even try catch blocks. thank you very much for reading this and helping me out.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload