1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mattbit\MysqlCompat\BridgeComponents; |
4
|
|
|
|
5
|
|
|
use Mattbit\MysqlCompat\Exception\QueryException; |
6
|
|
|
|
7
|
|
|
trait ExecuteQueries |
8
|
|
|
{ |
9
|
|
|
public function affectedRows(Connection $linkIdentifier = null) |
10
|
|
|
{ |
11
|
|
|
$connection = $this->manager->getOpenConnectionOrFail($linkIdentifier); |
|
|
|
|
12
|
|
|
|
13
|
|
|
return $connection->getRowCount(); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function query($query, Connection $linkIdentifier = null) |
17
|
|
|
{ |
18
|
|
|
$connection = $this->manager->getOpenConnectionOrFail($linkIdentifier); |
19
|
|
|
|
20
|
|
|
try { |
21
|
|
|
$result = $connection->query($query); |
22
|
|
|
} catch (QueryException $e) { |
23
|
|
|
return false; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
return $result; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function selectDb($databaseName, Connection $linkIdentifier = null) |
30
|
|
|
{ |
31
|
|
|
$connection = $this->manager->getOpenConnectionOrFail($linkIdentifier); |
32
|
|
|
|
33
|
|
|
return (bool) $connection->useDatabase($databaseName); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
View Code Duplication |
public function createDb($databaseName, Connection $linkIdentifier = null) |
37
|
|
|
{ |
38
|
|
|
$connection = $this->manager->getOpenConnectionOrFail($linkIdentifier); |
39
|
|
|
|
40
|
|
|
return $connection->parametrizedQuery( |
41
|
|
|
"CREATE DATABASE :databaseName", |
42
|
|
|
[':databaseName' => $databaseName] |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
View Code Duplication |
public function listTables($database, Connection $linkIdentifier = null) |
47
|
|
|
{ |
48
|
|
|
$connection = $this->manager->getOpenConnectionOrFail($linkIdentifier); |
49
|
|
|
|
50
|
|
|
return $connection->parametrizedQuery( |
51
|
|
|
"SHOW TABLES FROM :database", |
52
|
|
|
[':database' => $database] |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function insertId(Connection $linkIdentifier = null) |
57
|
|
|
{ |
58
|
|
|
$connection = $this->manager->getOpenConnectionOrFail($linkIdentifier); |
59
|
|
|
|
60
|
|
|
return (int) $connection->getLastInsertId(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function listDbs() |
64
|
|
|
{ |
65
|
|
|
// @todo |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function dbName() |
69
|
|
|
{ |
70
|
|
|
// @todo |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function dbQuery($database, $query, Connection $linkIdentifier = null) |
74
|
|
|
{ |
75
|
|
|
$connection = $this->manager->getOpenConnectionOrFail($linkIdentifier); |
76
|
|
|
$connection->useDatabase($database); |
77
|
|
|
|
78
|
|
|
return $connection->query($query); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function dropDb() |
82
|
|
|
{ |
83
|
|
|
// @todo |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function setCharset() |
87
|
|
|
{ |
88
|
|
|
// @todo |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function listFields() |
92
|
|
|
{ |
93
|
|
|
// @todo |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function listProcesses() |
97
|
|
|
{ |
98
|
|
|
// @todo |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function tablename() |
102
|
|
|
{ |
103
|
|
|
// @todo |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function unbufferedQuery() |
107
|
|
|
{ |
108
|
|
|
// @todo |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: