1: <?php
2:
3: /**
4: * Pry Framework
5: *
6: * LICENSE
7: *
8: * This source file is subject to the new BSD license that is bundled
9: * with this package in the file LICENSE.txt.
10: *
11: */
12:
13: namespace Pry\Log\Writer;
14:
15: /**
16: * Classe d'ecriture de log dans une base de données
17: *
18: * @package Log
19: * @subpackage Log_Writer
20: * @version 1.2.0
21: * @author Olivier ROGER <oroger.fr>
22: *
23: */
24: class Bd extends WriterAbstract
25: {
26:
27: private $table;
28:
29: /**
30: * Objet base de données
31: * @var Zend_Db_Adapter_Abstract
32: */
33: private $oSql;
34:
35: /**
36: * Constructeur
37: *
38: * @param string $table contenant les logs
39: * @param Zend_Db_Adapter_Abstract Objet sql
40: */
41: public function __construct($table, $sql)
42: {
43: $this->table = $table;
44: $this->oSql = $sql;
45: //var_dump($this->oSql);
46: }
47:
48: /**
49: * Log du message dans une base de données
50: *
51: * @param string $message
52: * @param string $level
53: * @access protected
54: */
55: protected function _write($message, $level)
56: {
57: $prefixe = ($this->mode == self::MODE_MINI) ? '' : '[' . date("d/m/Y - H:i:s") . '] (' . $this->txtSeverity[$level] . ') ';
58:
59: $prep = $this->oSql->prepare('INSERT INTO ' . $this->table . ' (level,date,message) VALUES(:level,:date,:message)');
60: $prep->execute(array(':level' => $level, ':date' => date("Y-m-d H:i:s"), ':message' => $prefixe . $message));
61: }
62:
63: }