1 <?php
2 /**
3 * Neevo - Tiny database layer for PHP. (http://neevo.smasty.net)
4 *
5 * This source file is subject to the MIT license that is bundled
6 * with this package in the file license.txt.
7 *
8 * Copyright (c) 2012 Smasty (http://smasty.net)
9 *
10 */
11
12 namespace Neevo;
13
14
15 /**
16 * Interface implemented by all Neevo drivers.
17 *
18 * All Neevo drivers **must** implement this interface, not only reproduce all it's
19 * methods, or they won't be recognised as valid drivers.
20 *
21 * If something is not implemented, the method **must** throw Neevo\Drivers\ImplementationException.
22 * The exception will be catched and Neevo will decide, what to do next.
23 *
24 * If something is not supported by the driver (e.g. number of result rows on unbuffered queries)
25 * the driver should throw Neevo\DriverException.
26 *
27 * When the driver needs to rewrite default output of SQL commands, it **must**
28 * extend **Neevo\Parser** class. For proper use, see
29 * "source of **Neevo\Parser** class":https://github.com/smasty/Neevo/blob/master/src/Neevo/Parser.php.
30 *
31 * @author Smasty
32 */
33 interface DriverInterface {
34
35
36 /**
37 * Checks for required PHP extension.
38 * @throws DriverException
39 */
40 public function __construct();
41
42
43 /**
44 * Creates connection to database.
45 * @param array $config Configuration options
46 */
47 public function connect(array $config);
48
49
50 /**
51 * Closes the connection.
52 */
53 public function closeConnection();
54
55
56 /**
57 * Frees memory used by given result.
58 * @param resource $resultSet
59 * @return bool
60 */
61 public function freeResultSet($resultSet);
62
63
64 /**
65 * Executes given SQL statement.
66 * @param string $queryString
67 * @return resource|bool
68 */
69 public function runQuery($queryString);
70
71
72 /**
73 * Begins a transaction if supported.
74 * @param string $savepoint
75 */
76 public function beginTransaction($savepoint = null);
77
78
79 /**
80 * Commits statements in a transaction.
81 * @param string $avepoint
82 */
83 public function commit($savepoint = null);
84
85
86 /**
87 * Rollbacks changes in a transaction.
88 * @param string $savepoint
89 */
90 public function rollback($savepoint = null);
91
92
93 /**
94 * Fetches row from given result set as an associative array.
95 * @param resource $resultSet
96 * @return array
97 */
98 public function fetch($resultSet);
99
100
101 /**
102 * Moves internal result pointer.
103 * @param resource $resultSet
104 * @param int $offset
105 * @return bool
106 */
107 public function seek($resultSet, $offset);
108
109
110 /**
111 * Returns the ID generated in the INSERT statement.
112 * @return int
113 */
114 public function getInsertId();
115
116
117 /**
118 * Randomizes result order.
119 * @param BaseStatement $statement
120 */
121 public function randomizeOrder(BaseStatement $statement);
122
123
124 /**
125 * Returns the number of rows in the given result set.
126 * @param resource $resultSet
127 * @return int|bool
128 */
129 public function getNumRows($resultSet);
130
131
132 /**
133 * Returns the number of affected rows in previous operation.
134 * @return int
135 */
136 public function getAffectedRows();
137
138
139 /**
140 * Escapes given value.
141 * @param mixed $value
142 * @param string $type
143 * @return mixed
144 */
145 public function escape($value, $type);
146
147
148 /**
149 * Decodes given value.
150 * @param mixed $value
151 * @param string $type
152 * @return mixed
153 */
154 public function unescape($value, $type);
155
156
157 /**
158 * Returns the PRIMARY KEY column for given table.
159 * @param string $table
160 * @return string|NULL
161 */
162 public function getPrimaryKey($table);
163
164
165 /**
166 * Returns types of columns in given result set.
167 * @param resource $resultSet
168 * @param string $table
169 * @return array
170 */
171 public function getColumnTypes($resultSet, $table);
172
173
174 }
175