~ubuntu-branches/ubuntu/saucy/horde3/saucy

« back to all changes in this revision

Viewing changes to lib/Horde/SessionHandler/sapdb.php

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2005-05-04 23:08:08 UTC
  • Revision ID: james.westby@ubuntu.com-20050504230808-p4hf3hk28o3v7wir
Tags: upstream-3.0.4
ImportĀ upstreamĀ versionĀ 3.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
require_once dirname(__FILE__) . '/sql.php';
 
4
 
 
5
/**
 
6
 * SessionHandler implementation for PHP's PEAR database abstraction layer.
 
7
 *
 
8
 * If you access your database through ODBC, you will almost certainly need
 
9
 * to change PHP's default value for odbc.defaultlrl (this is a php.ini
 
10
 * setting). The default is 4096, which is too small (your session data will
 
11
 * data will be chopped off), and setting it to 0 DOES NOT work - that
 
12
 * doesn't mean no limit, for some reason. odbc.defaultlrl = 32768
 
13
 * seems to work pretty well (using MSSQL-2000).
 
14
 *
 
15
 * Required values for $params:<pre>
 
16
 *     'hostspec'  --  The hostname of the database server.
 
17
 *     'protocol'  --  The communication protocol ('tcp', 'unix', etc.).
 
18
 *     'username'  --  The username with which to connect to the database.
 
19
 *     'password'  --  The password associated with 'username'.
 
20
 *     'database'  --  The name of the database.
 
21
 *     'table'     --  The name of the sessiondata table in 'database'.</pre>
 
22
 *
 
23
 * The table structure can be created by the scripts/db/sessionhandler.sql
 
24
 * script.
 
25
 *
 
26
 * $Horde: framework/SessionHandler/SessionHandler/sapdb.php,v 1.13.12.2 2005/02/01 19:07:15 chuck Exp $
 
27
 *
 
28
 * Copyright 2002-2005 Mike Cochrane <mike@graftonhall.co.nz>
 
29
 *
 
30
 * See the enclosed file COPYING for license information (LGPL). If you
 
31
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 
32
 *
 
33
 * @author  Mike Cochrane <mike@graftonhall.co.nz>
 
34
 * @since   Horde 3.0
 
35
 * @package Horde_SessionHandler
 
36
 */
 
37
class SessionHandler_sapdb extends SessionHandler_sql {
 
38
 
 
39
    /** Hash containing connection parameters. */
 
40
    var $_params = array();
 
41
 
 
42
    /** Handle for the current database connection.
 
43
        @var object DB $db */
 
44
    var $_db;
 
45
 
 
46
    /**
 
47
     * Boolean indicating whether or not we're connected to the SQL
 
48
     * server. */
 
49
    var $_connected = false;
 
50
 
 
51
    /**
 
52
     * Constructs a new SQL SessionHandler object.
 
53
     *
 
54
     * @param array  $params    A hash containing connection parameters.
 
55
     */
 
56
    function SessionHandler_sapdb($params = array())
 
57
    {
 
58
        $this->_params = $params;
 
59
        $this->_params['phptype'] = 'odbc';
 
60
    }
 
61
 
 
62
    function read($id)
 
63
    {
 
64
        /* Make sure we have a valid database connection. */
 
65
        $this->_connect();
 
66
 
 
67
        /* Build the SQL query. */
 
68
        $query = sprintf('SELECT session_data FROM %s WHERE session_id = %s',
 
69
                         $this->_params['table'],
 
70
                         $this->_db->quote($id));
 
71
 
 
72
        /* Log the query at a DEBUG log level. */
 
73
        Horde::logMessage(sprintf('SQL Query by SessionHandler_sql::read(): query = "%s"', $query),
 
74
                          __FILE__, __LINE__, PEAR_LOG_DEBUG);
 
75
 
 
76
        /* Execute the query */
 
77
        $result = odbc_exec($this->_db->connection, $query);
 
78
        odbc_longreadlen($result, 1024*1024);
 
79
 
 
80
        /* Fetch the value */
 
81
        odbc_fetch_row($result, 0);
 
82
        $data = odbc_result($result, 'session_data');
 
83
 
 
84
        /* Clean up */
 
85
        odbc_free_result($result);
 
86
 
 
87
        return $data;
 
88
    }
 
89
 
 
90
}