]>
git.datanom.net - qtadmin.git/blob - lib/db_mysqli.inc.php
2 /* vim: set ts=4 tw=0 sw=4 noet: */
3 require_once $CFG->root
.'lib/db_implementation.php';
5 class DBMysqli
extends DBImpl
{
7 private static $_instance = null;
9 private $charset = 'utf8';
10 private $numRows = -1;
12 private function __construct() {
16 function __destruct() {
23 private function __clone() {}
25 public static function getInstance() {
26 if (!is_object(self
::$_instance)) {
27 self
::$_instance = new DBMysqli();
29 return self
::$_instance;
32 private function connect() {
36 $this->con
= new mysqli($CFG->amavisd_db_host
, $CFG->amavisd_db_user
,
37 $CFG->amavisd_db_password
, $CFG->amavisd_db_name
,
38 $CFG->amavisd_db_port
);
39 if ($this->con
->connect_error
) {
40 die ('Connect error ('.$this->con
->connect_errno
.') '.
41 $this->con
->connect_error
);
46 public function setCharset($charset = 'utf8') {
47 $this->charset
= $charset;
50 private function changeCharset() {
51 if (!$this->con
->set_charset($this->charset
)) {
52 printf("Error loading character set %s: %s\n", $this->charset
, $this->con
->error
);
56 public function update($sql) {
59 if (! is_array($sql)) {
63 $this->con
->autocommit(false);
64 foreach ($sql as $query) {
65 $this->con
->query($query) ?
null : $success = false;
67 $success ?
$this->con
->commit() : $this->con
->rollback();
68 $this->con
->autocommit(true);
73 function getMarked($recipient = 'all') {
76 $query = "select distinct m.mail_id as id from quarantine q, msgrcpt m, msgs s, maddr r ";
77 $query .= "where m.mail_id = q.mail_id and q.mail_id = s.mail_id and m.rid = r.id ";
78 $query .= "and (m.rs = 'R' or m.rs = 'D')";
80 if ($recipient != 'all') {
81 $query .= " and email = '$recipient'";
84 if ($result = $this->con
->query($query)) {
85 while ($row = $result->fetch_object()) {
93 public function getQMails($offset = -1, $rowsPerPage = -1, $recipient = 'all') {
95 $this->changeCharset();
96 $query = "SELECT DISTINCT quarantine.mail_id, secret_id, rs, bspam_level, ";
97 $query .= "(UNIX_TIMESTAMP(time_iso) + (3600 * 2)) AS time_iso, ";
98 $query .= "SUBSTRING(sender.email,1,35) AS sender, ";
99 $query .= "SUBSTRING(recipient.email,1,28) AS recipient, size, msgrcpt.content ";
100 $query .= "AS quaratinefor, SUBSTRING( subject, 1, 25) AS subject FROM ";
101 $query .= "`quarantine` LEFT JOIN msgrcpt ON msgrcpt.mail_id = quarantine.mail_id ";
102 $query .= "LEFT JOIN msgs ON msgs.mail_id = quarantine.mail_id LEFT JOIN maddr AS ";
103 $query .= "recipient ON msgrcpt.rid = recipient.id LEFT JOIN maddr AS sender ON ";
104 $query .= "msgs.sid = sender.id WHERE msgrcpt.rs != 'R' AND msgrcpt.rs != 'D'";
106 if ($recipient != 'all') {
107 $query .= " and recipient.email = '$recipient'";
110 if ($offset >= 0 && $rowsPerPage >= 0) {
111 $result = $this->con
->query($query, MYSQLI_STORE_RESULT
);
113 $this->numRows
= $result->num_rows
;
118 $query .= " ORDER BY time_iso DESC LIMIT $offset, $rowsPerPage";
121 if ($result = $this->con
->query($query, MYSQLI_USE_RESULT
)) {
122 if ($this->numRows
< 0)
123 $this->numRows
= $result->num_rows
;
124 while ($obj = $result->fetch_object()) {
133 public function numRows() {
134 return $this->numRows
;
137 public function getMail($id) {
140 $this->changeCharset();
141 $query = "SELECT * FROM quarantine WHERE mail_id = '$id'";
142 if ($result = $this->con
->query($query, MYSQLI_USE_RESULT
)) {
143 $row = $result->fetch_object();
This page took 0.11252 seconds and 6 git commands to generate.