php author Mednikov Yuriy version created 19-сен-2008 15 20 14 define

  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
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* @author Mednikov G Yuriy
* @version 1.0
* @created 19-сен-2008 15:20:14
*/
define('MYSQL_CONNECT_SINGLE', 10000);
define('MYSQL_CONNECT_PERMANENT', 10001);
define('DB_SELECT', 11001);
define('DB_INSERT', 11002);
define('DB_UPDATE', 11003);
define('DB_DELETE', 11004);
class MySQL implements Interface_Database {
// Objects
protected static
$dbh = null,
$instance = null;
// Connection data
protected static
$_HOST,
$_USER,
$_PASS,
$_NAME,
$_MODE;
public static function getInstance() {
if(!is_object(self::$instance)) {
self::$instance = new self;
}
return self::$instance;
}
protected function __construct() {
if(!function_exists('mysql_connect')) {
throw new ErrorException('MySQL-library not found. Please, check Your PHP configuration and PHP2MySQL bridging', E_ERROR);
}
}
protected function __destruct() {
$this->disconnect();
}
public function setConnectionData() {
$args = func_get_args();
if(sizeof($args) != 4) {
throw new Exception('MySQL::connect expect 4 params: MySQL HOST, MySQL USER, MySQL PASSWORD, MySQL Connection type (Permanent/Temporary)');
}
list(self::$_HOST, self::$_USER, self::$_PASS, self::$_MODE) = func_get_args();
}
public function connect() {
if(self::$_MODE == MYSQL_CONNECT_PERMANENT) {
try {
self::$dbh = mysql_pconnect(self::$_HOST, self::$_USER, self::$_PASS);
} catch (Exception $e) {
// print_r($e);
}
} else {
try {
self::$dbh = mysql_connect(self::$_HOST, self::$_USER, self::$_PASS);
} catch (Exception $e) {
print_r($e);
}
}
}
public function disconnect() {
if(self::$_MODE != MYSQL_CONNECT_PERMANENT) {
mysql_close(self::$dbh);
}
}
public function reconnect() {
$this->disconnect();
$this->connect();
}
protected function validateConnectionData () {
if(self::$_HOST == null) {
throw new Exception('Database host isn`t defined');
}
if(self::$_USER == null) {
throw new Exception('Database user isn`t defined');
}
if(self::$_NAME == null) {
throw new Exception('Database name isn`t defined');
}
if(self::$_MODE != MYSQL_CONNECT_PERMANENT) {
self::$_MODE = MYSQL_CONNECT_SINGLE;
}
}
protected function callSystem() {
if(!class_exists('LSF_System')) {
class System {
public function __call() {}
public function __isset() {}
}
}
}
/**
* ORM SECTION
*/
}