16 if (!class_exists(
'DB')) {
17 require_once
'DB.php';
123 $this->_id = md5(microtime());
124 $this->_table =
$name;
128 if (!empty($conf[
'sql'])) {
129 $this->_sql = $conf[
'sql'];
131 $this->_sql =
'INSERT INTO ' . $this->_table .
132 ' (id, logtime, ident, priority, message)' .
133 ' VALUES(?, CURRENT_TIMESTAMP, ?, ?, ?)';
137 if (isset($conf[
'options']) && is_array($conf[
'options'])) {
138 $this->_options = $conf[
'options'];
142 if (!empty($conf[
'sequence'])) {
143 $this->_sequence = $conf[
'sequence'];
147 if (isset($conf[
'identLimit'])) {
148 $this->_identLimit = $conf[
'identLimit'];
155 if (isset($conf[
'db'])) {
156 $this->_db = &$conf[
'db'];
157 $this->_existingConnection =
true;
158 $this->_opened =
true;
160 $this->_dsn = $conf[
'dsn'];
173 if (!$this->_opened) {
175 $this->_db = &DB::connect($this->_dsn, $this->_options);
176 if (DB::isError($this->_db)) {
186 $this->_opened =
true;
202 if ($this->_opened && !$this->_existingConnection) {
203 $this->_opened =
false;
204 $this->_db->freePrepared($this->_statement);
205 return $this->_db->disconnect();
208 return ($this->_opened ===
false);
223 $this->_ident = substr($ident, 0, $this->_identLimit);
239 function log($message, $priority = null)
242 if ($priority === null) {
252 if (!$this->_opened && !$this->
open()) {
265 $id = $this->_db->nextId($this->_sequence);
266 $values = array($id, $this->_ident, $priority, $message);
269 $result =& $this->_db->execute($this->_statement, $values);
274 $this->
_announce(array(
'priority' => $priority,
'message' => $message));
289 $this->_statement = $this->_db->prepare($this->_sql);
292 return (DB::isError($this->_statement) ===
false);