1: <?php
2: /**
3: * Kolab storage implementation for the Horde_Db database abstraction layer.
4: *
5: * Copyright 2007-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file COPYING for license information (GPL). If you
8: * did not receive this file, see http://www.horde.org/licenses/gpl.
9: *
10: * @author Your Name <you@example.com>
11: * @category Horde
12: * @package Kolab
13: */
14: class Kolab_Driver_Sql extends Kolab_Driver
15: {
16: /**
17: * Handle for the current database connection.
18: *
19: * @var Horde_Db_Adapter
20: */
21: protected $_db;
22:
23: /**
24: * Storage variable.
25: *
26: * @var array
27: */
28: protected $_foo = array();
29:
30: /**
31: * Constructs a new SQL storage object.
32: *
33: * @param array $params Class parameters:
34: * - db: (Horde_Db_Adapater) A database handle.
35: * - table: (string, optional) The name of the
36: * database table.
37: *
38: * @throws InvalidArgumentException
39: */
40: public function __construct(array $params = array())
41: {
42: if (!isset($params['db'])) {
43: throw new InvalidArgumentException('Missing db parameter.');
44: }
45: $this->_db = $params['db'];
46: unset($params['db']);
47:
48: $params = array_merge($params, array(
49: 'table' => 'kolab_foo'
50: ), $params);
51:
52: parent::__construct($params);
53: }
54:
55: /**
56: * Retrieves the foos from the database.
57: *
58: * @throws Kolab_Exception
59: */
60: public function retrieve()
61: {
62: /* Build the SQL query. */
63: $query = 'SELECT * FROM ' . $this->_params['table'] . ' WHERE foo = ?';
64: $values = array($this->_params['bar']);
65:
66: /* Execute the query. */
67: try {
68: $rows = $this->_db->selectAll($query, $values);
69: } catch (Horde_Db_Exception $e) {
70: throw new Kolab_Exception($e);
71: }
72:
73: /* Store the retrieved values in the foo variable. */
74: $this->_foo = array_merge($this->_foo, $rows);
75: }
76: }
77: