- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
require_once('adodb/adodb.inc.php');
class adoDbConnector
{
private static $instance = null;
public static function getInstance()
{
if (self::$instance == NULL)
{
self::$instance = new adoDbConnector();
}
return self::$instance;
}
private function __construct() { }
public function __clone()
{
trigger_error('No __clone()!', E_USER_ERROR);
}
public function __wakeup()
{
trigger_error('No __wakeup()!', E_USER_ERROR);
}
public function connect($connectionType, $connectionData)
{
switch($connectionType)
{
case 0:
return self::generalConnect($connectionData);
break;
case 1:
return self::dsnConnect($connectionData);
break;
case 2:
return self::xmlConnect($connectionData);
break;
default:
throw new Exception('Wrong type of connection!');
}
}
private static function generalConnect($connectionData)
{
if(is_array($connectionData))
{
$conn = &ADONewConnection($connectionData[0]);
$conn->PConnect($connectionData[1], $connectionData[2],
$connectionData[3], $connectionData[4]);
return $conn;
}
else throw new Exception('Wrong type of connection data, must be an array!');
}
private static function dsnConnect($connectionData)
{
if(is_string($connectionData))
{
$conn = ADONewConnection($connectionData);
return $conn;
}
else throw new Exception('Wrong type of connection data, must be a string!');
}
private static function xmlConnect($connectionData)
{
if(is_string($connectionData) && file_exists($connectionData))
{
$xml = simplexml_load_file($connectionData);
foreach($xml as $x)
{
$connArr[] = trim($x);
}
$conn = &ADONewConnection($connArr[0]);
$conn->PConnect($connArr[1], $connArr[2], $connArr[3], $connArr[4]);
return $conn;
}
else throw new Exception('Wrong file name or connection type!');
}
}
Archont12 29.03.2012 20:46 # −2
guest 30.03.2012 13:01 # 0
Vasiliy 30.03.2012 13:47 # 0
roman-kashitsyn 30.03.2012 14:18 # 0
guest8 09.04.2019 12:57 # −999