forked from guahan-web/PHP-SimpleQueue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleQueueDB.php
More file actions
executable file
·67 lines (60 loc) · 1.46 KB
/
SimpleQueueDB.php
File metadata and controls
executable file
·67 lines (60 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* @fileoverview
* @author Garth Henson (http://www.guahanweb.com)
* @since 1.0
* @version 1.0
*/
/**
* Abstraction layer that allows for a singleton instance of a
* database connection to be used across the queue
*
* @author Garth Henson (http://www.guahanweb.com)
*/
class SimpleQueueDB {
static protected $user = '';
static protected $pass = '';
static protected $host = '';
static protected $dbname = '';
static protected $instance;
static public $errors = array();
/**
* Gets a singleton instance of the database connection
*
* @static
* @access public
* @return SimpleQueueDB
*/
static public function getInstance() {
if (NULL === self::$instance) {
self::$instance = self::connect();
if (FALSE === self::$instance) {
$err = implode("\n\n", self::$errors);
$msg = "Database error occurred. Turn on debugging to see detailed errors.\n\n";
if (defined('DEBUG') && TRUE === DEBUG) {
$msg .= $err;
}
throw new Exception($msg);
}
}
return self::$instance;
}
/**
* Connects to the database with the currently defined credentials
*
* @static
* @access protected
* @return void
*/
static protected function connect() {
if (FALSE === ($con = @mysql_connect(self::$host, self::$user, self::$pass, TRUE))) {
self::$errors[] = @mysql_error();
} elseif (FALSE === @mysql_select_db(self::$dbname, $con)) {
self::$errors[] = @mysql_error();
} else {
return $con;
}
return FALSE;
}
}
?>