public function write( $sessionId, $sessionData )
    {
        $db = eZDB::instance();
        if ( !$db->isConnected() )
        {
            return false;
        }

        $ini = eZINI::instance();
        $expirationTime = time() + $ini->variable( 'Session', 'SessionTimeout' );

        if ( $db->bindingType() != eZDBInterface::BINDING_NO )
        {
            $sessionData = $db->bindVariable( $sessionData, array( 'name' => 'data' ) );
        }
        else
        {
            $sessionData = '\'' . $db->escapeString( $sessionData ) . '\'';
        }
        $escKey = $db->escapeString( $sessionId );
        $userID = $db->escapeString( eZSession::userID() );

        // check if session already exists
        $sessionRes = !$this->userHasCookie ? false : $db->arrayQuery( "SELECT session_key FROM ezsession WHERE session_key='$escKey'" );

        if ( $sessionRes !== false and count( $sessionRes ) == 1 )
        {
            $ret = $db->query( "UPDATE ezsession SET expiration_time='$expirationTime', data=$sessionData, user_id='$userID' WHERE session_key='$escKey'" );
        }
        else
        {
            $insertQuery = "INSERT INTO ezsession ( session_key, expiration_time, data, user_id )
                        VALUES ( '$escKey', '$expirationTime', $sessionData, '$userID' )";
            $ret = $db->query( $insertQuery );
        }
        return true;
    }