This repository was archived by the owner on Mar 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.php
More file actions
89 lines (75 loc) Β· 2.01 KB
/
Database.php
File metadata and controls
89 lines (75 loc) Β· 2.01 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace Library\Sql;
use Library\Exceptions as Excs;
use Library\Utilities\UtilitiesService;
final class Database
{
public $Config;
public $AffectedRows;
public $ClientInfo;
public $ClientVersion;
public $ConnectErrno;
public $ConnectError;
public $Errno;
public $ErrorList;
public $Error;
public $FieldCount;
public $HostInfo;
public $ProtocolVersion;
public $ServerInfo;
public $ServerVersion;
public $Info;
public $InsertId;
public $SqlState;
public $ThreadId;
public $WarningCount;
private $db;
public function __construct($config)
{
if(UtilitiesService::GetClassName($config) != "DatabaseConfig")
{
throw new Excs\ArgumentException("Invalid configuration object");
}
$this->Config = $config;
}
public function Connect()
{
$this->db = $this->Config->CreateNewConnection();
$this->SetPropsForOperation();
$this->ClientInfo = $this->db->client_info;
$this->ClientVersion = $this->db->client_version;
$this->ConnectErrno = $this->db->connect_errno;
$this->ConnectError = $this->db->connect_error;
$this->FieldCount = $this->db->field_count;
$this->HostInfo = $this->db->host_info;
$this->ServerVersion = $this->db->server_version;
$this->ServerInfo = $this->db->server_info;
$this->ProtocolVersion = $this->db->protocol_version;
$this->ThreadId = $this->db->thread_id;
}
public function Close()
{
$this->db->close();
}
public function Query($query)
{
if(UtilitiesService::GetParentClassName($query) == "BaseQuery")
{
$query = $query->toSql();
}
$result = $this->db->query($query);
$this->SetPropsForOperation();
$this->AffectedRows = $this->db->affected_rows;
$this->Info = $this->db->info;
$this->InsertId = $this->db->insert_id;
$this->WarningCount = $this->db->warning_count;
return new ResultSet($result);
}
private function SetPropsForOperation()
{
$this->SqlState = $this->db->sqlstate;
$this->Errno = $this->db->errno;
$this->Error = $this->db->error;
$this->ErrorList = $this->db->error_list;
}
}