function write($session_id, $session_data)
{
// insert OR update session's data - this is how it works:
// first it tries to insert a new row in the database BUT if session_id is already in the database then just
// update session_data and session_expire for that specific session_id
// read more here http://dev.mysql.com/doc/refman/4.1/en/insert-on-duplicate.html
$result = $this->_mysql_query('
INSERT INTO
' . $this->table_name . ' (
session_id,
hash,
session_data,
session_expire
)
VALUES (
"' . $this->_mysql_real_escape_string($session_id) . '",
"' . $this->_mysql_real_escape_string(md5(($this->lock_to_user_agent && isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '') . ($this->lock_to_ip && isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '') . $this->security_code)) . '",
"' . $this->_mysql_real_escape_string($session_data) . '",
"' . $this->_mysql_real_escape_string(time() + $this->session_lifetime) . '"
)
ON DUPLICATE KEY UPDATE
session_data = "' . $this->_mysql_real_escape_string($session_data) . '",
session_expire = "' . $this->_mysql_real_escape_string(time() + $this->session_lifetime) . '"
') or die($this->_mysql_error());
// if anything happened
if ($result) {
// note that after this type of queries, mysqli_affected_rows() returns
// - 1 if the row was inserted
// - 2 if the row was updated
// if the row was updated
// return TRUE
if (@$this->_mysql_affected_rows() > 1) {
return true;
} else {
return '';
}
}
// if something went wrong, return false
return false;
}