10 require_once
'MDB2.php';
100 'logtime' =>
'timestamp',
102 'priority' =>
'text',
115 function Log_mdb2($name, $ident =
'', $conf = array(),
118 $this->_id = md5(microtime());
119 $this->_table = $name;
123 if (isset($conf[
'options']) && is_array($conf[
'options'])) {
124 $this->_options = $conf[
'options'];
128 if (!empty($conf[
'sequence'])) {
129 $this->_sequence = $conf[
'sequence'];
133 if (isset($conf[
'identLimit'])) {
134 $this->_identLimit = $conf[
'identLimit'];
141 if (isset($conf[
'db'])) {
142 $this->_db = &$conf[
'db'];
143 $this->_existingConnection =
true;
144 $this->_opened =
true;
145 } elseif (isset($conf[
'singleton'])) {
147 $this->_existingConnection =
true;
148 $this->_opened =
true;
150 $this->_dsn = $conf[
'dsn'];
163 if (!$this->_opened) {
176 $this->_opened =
true;
193 if (is_object($this->_statement)) {
194 $this->_statement->free();
195 $this->_statement = null;
199 if ($this->_opened && !$this->_existingConnection) {
200 $this->_opened =
false;
201 return $this->_db->disconnect();
204 return ($this->_opened ===
false);
219 $this->_ident = substr($ident, 0, $this->_identLimit);
235 function log($message, $priority = null)
238 if ($priority === null) {
248 if (!$this->_opened && !$this->
open()) {
262 'id' => $this->_db->nextId($this->_sequence),
265 'priority' => $priority,
266 'message' => $message
271 $result = &$this->_statement->execute($values);
272 $this->_db->popExpect();
287 $this->_statement->free();
293 $result = $this->_statement->execute($values);
299 $this->
_announce(array(
'priority' => $priority,
'message' => $message));
312 $this->_db->loadModule(
'Manager', null,
true);
313 $result = $this->_db->manager->createTable(
316 'id' => array(
'type' => $this->_types[
'id']),
317 'logtime' => array(
'type' => $this->_types[
'logtime']),
318 'ident' => array(
'type' => $this->_types[
'ident']),
319 'priority' => array(
'type' => $this->_types[
'priority']),
320 'message' => array(
'type' => $this->_types[
'message'])
327 $result = $this->_db->manager->createIndex(
330 array(
'fields' => array(
'id' =>
true),
'unique' =>
true)
349 $this->_statement = &$this->_db->prepare(
350 'INSERT INTO ' . $this->_table .
351 ' (id, logtime, ident, priority, message)' .
352 ' VALUES(:id, :logtime, :ident, :priority, :message)',