|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// Copyright (c) Dmitry Kosenkov, All rights reserved. |
|
4
|
|
|
|
|
5
|
|
|
namespace HSAL; |
|
6
|
|
|
|
|
7
|
|
|
abstract class Driver |
|
8
|
|
|
{ |
|
9
|
|
|
public $database; |
|
10
|
|
|
public $host; |
|
11
|
|
|
public $port_read = 9998; |
|
12
|
|
|
public $port_write = 9999; |
|
13
|
|
|
|
|
14
|
|
|
protected $options = []; |
|
15
|
|
|
|
|
16
|
|
|
public function __construct($host, $database, Array $options) |
|
17
|
|
|
{ |
|
18
|
|
|
$this->database = $database; |
|
19
|
|
|
$this->host = $host; |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
if (!empty($options)) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->options = $options; |
|
25
|
|
|
|
|
26
|
|
|
$this->port_read = isset($options['port_read']) ? $this->options['port_read'] : $this->port_read; |
|
27
|
|
|
$this->port_write = isset($options['port_write']) ? $this->options['port_write'] : $this->port_write; |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
public function fetchColumn($table, $field, $index, Array $condition, $operator) |
|
34
|
|
|
{ |
|
35
|
|
|
$result = $this->fetchArray($table, [$field], $index, $condition, $operator); |
|
36
|
|
|
|
|
37
|
|
|
return empty($result) ? FALSE : $result[0]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function fetchAssoc($table, Array $fields, $index, Array $condition, $operator) |
|
41
|
|
|
{ |
|
42
|
|
|
$result = $this->fetchArray($table, $fields, $index, $condition, $operator); |
|
43
|
|
|
|
|
44
|
|
|
if (!empty($result)) |
|
45
|
|
|
return array_combine($fields, $result); |
|
46
|
|
|
else |
|
47
|
|
|
return FALSE; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getTableDatabase($table) |
|
51
|
|
|
{ |
|
52
|
|
|
$database = $this->database; |
|
53
|
|
|
|
|
54
|
|
|
if (strpos($table, '.')) |
|
55
|
|
|
{ |
|
56
|
|
|
list($database, $table) = explode('.', $table); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return [$database, $table]; |
|
60
|
|
|
} |
|
61
|
|
|
} |