1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mattbit\MysqlCompat\BridgeComponents; |
4
|
|
|
|
5
|
|
|
use Mattbit\MysqlCompat\Connection; |
6
|
|
|
use Mattbit\MysqlCompat\Exception\QueryException; |
7
|
|
|
|
8
|
|
|
trait ExecuteQueries |
9
|
|
|
{ |
10
|
|
|
public function affectedRows(Connection $linkIdentifier = null) |
11
|
|
|
{ |
12
|
|
|
$connection = $this->manager->getOpenConnectionOrFail($linkIdentifier); |
13
|
|
|
|
14
|
|
|
return $connection->getRowCount(); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function query($query, Connection $linkIdentifier = null) |
18
|
|
|
{ |
19
|
|
|
$connection = $this->manager->getOpenConnectionOrFail($linkIdentifier); |
20
|
|
|
|
21
|
|
|
try { |
22
|
|
|
$result = $connection->query($query); |
23
|
|
|
} catch (QueryException $e) { |
24
|
|
|
return false; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
return $result; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function selectDb($databaseName, Connection $linkIdentifier = null) |
31
|
|
|
{ |
32
|
|
|
$connection = $this->manager->getOpenConnectionOrFail($linkIdentifier); |
33
|
|
|
|
34
|
|
|
return (bool) $connection->useDatabase($databaseName); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
View Code Duplication |
public function createDb($databaseName, Connection $linkIdentifier = null) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$connection = $this->manager->getOpenConnectionOrFail($linkIdentifier); |
40
|
|
|
|
41
|
|
|
return $connection->parametrizedQuery( |
42
|
|
|
'CREATE DATABASE :databaseName', |
43
|
|
|
[':databaseName' => $databaseName] |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
public function listTables($database, Connection $linkIdentifier = null) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$connection = $this->manager->getOpenConnectionOrFail($linkIdentifier); |
50
|
|
|
|
51
|
|
|
return $connection->parametrizedQuery( |
52
|
|
|
'SHOW TABLES FROM :database', |
53
|
|
|
[':database' => $database] |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function insertId(Connection $linkIdentifier = null) |
58
|
|
|
{ |
59
|
|
|
$connection = $this->manager->getOpenConnectionOrFail($linkIdentifier); |
60
|
|
|
|
61
|
|
|
return (int) $connection->getLastInsertId(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function listDbs() |
65
|
|
|
{ |
66
|
|
|
// @todo |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function dbName() |
70
|
|
|
{ |
71
|
|
|
// @todo |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function dbQuery($database, $query, Connection $linkIdentifier = null) |
75
|
|
|
{ |
76
|
|
|
$connection = $this->manager->getOpenConnectionOrFail($linkIdentifier); |
77
|
|
|
$connection->useDatabase($database); |
78
|
|
|
|
79
|
|
|
return $connection->query($query); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function dropDb() |
83
|
|
|
{ |
84
|
|
|
// @todo |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function listFields() |
88
|
|
|
{ |
89
|
|
|
// @todo |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function listProcesses() |
93
|
|
|
{ |
94
|
|
|
// @todo |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function tablename() |
98
|
|
|
{ |
99
|
|
|
// @todo |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function unbufferedQuery() |
103
|
|
|
{ |
104
|
|
|
// @todo |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.