1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Mysql\PDO; |
6
|
|
|
|
7
|
|
|
use PDO; |
8
|
|
|
use Yiisoft\Db\Command\CommandInterface; |
9
|
|
|
use Yiisoft\Db\Connection\ConnectionPDO; |
10
|
|
|
use Yiisoft\Db\Exception\Exception; |
11
|
|
|
use Yiisoft\Db\Exception\InvalidConfigException; |
12
|
|
|
use Yiisoft\Db\Mysql\Quoter; |
13
|
|
|
use Yiisoft\Db\Query\QueryBuilderInterface; |
|
|
|
|
14
|
|
|
use Yiisoft\Db\Schema\QuoterInterface; |
15
|
|
|
use Yiisoft\Db\Schema\SchemaInterface; |
16
|
|
|
use Yiisoft\Db\Transaction\TransactionInterface; |
17
|
|
|
|
18
|
|
|
use function constant; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Database connection class prefilled for MySQL Server. |
22
|
|
|
* The class Connection represents a connection to a database via [PDO](https://secure.php.net/manual/en/book.pdo.php). |
23
|
|
|
*/ |
24
|
|
|
final class ConnectionPDOMysql extends ConnectionPDO |
25
|
|
|
{ |
26
|
348 |
|
public function createCommand(?string $sql = null, array $params = []): CommandInterface |
27
|
|
|
{ |
28
|
348 |
|
$command = new CommandPDOMysql($this, $this->queryCache); |
29
|
|
|
|
30
|
348 |
|
if ($sql !== null) { |
31
|
173 |
|
$command->setSql($sql); |
32
|
|
|
} |
33
|
|
|
|
34
|
348 |
|
if ($this->logger !== null) { |
35
|
348 |
|
$command->setLogger($this->logger); |
36
|
|
|
} |
37
|
|
|
|
38
|
348 |
|
if ($this->profiler !== null) { |
39
|
348 |
|
$command->setProfiler($this->profiler); |
40
|
|
|
} |
41
|
|
|
|
42
|
348 |
|
return $command->bindValues($params); |
43
|
|
|
} |
44
|
|
|
|
45
|
8 |
|
public function createTransaction(): TransactionInterface |
46
|
|
|
{ |
47
|
8 |
|
return new TransactionPDOMysql($this); |
48
|
|
|
} |
49
|
|
|
|
50
|
10 |
|
public function getDriverName(): string |
51
|
|
|
{ |
52
|
10 |
|
return 'mysql'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @throws Exception|InvalidConfigException |
57
|
|
|
*/ |
58
|
348 |
|
public function getQueryBuilder(): QueryBuilderInterface |
59
|
|
|
{ |
60
|
348 |
|
if ($this->queryBuilder === null) { |
61
|
348 |
|
$this->queryBuilder = new QueryBuilderPDOMysql( |
62
|
348 |
|
$this->createCommand(), |
63
|
348 |
|
$this->getQuoter(), |
64
|
348 |
|
$this->getSchema(), |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
348 |
|
return $this->queryBuilder; |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
365 |
|
public function getQuoter(): QuoterInterface |
72
|
|
|
{ |
73
|
365 |
|
if ($this->quoter === null) { |
74
|
365 |
|
$this->quoter = new Quoter('`', '`', $this->getTablePrefix()); |
75
|
|
|
} |
76
|
|
|
|
77
|
365 |
|
return $this->quoter; |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
374 |
|
public function getSchema(): SchemaInterface |
81
|
|
|
{ |
82
|
374 |
|
if ($this->schema === null) { |
83
|
374 |
|
$this->schema = new SchemaPDOMysql($this, $this->schemaCache); |
84
|
|
|
} |
85
|
|
|
|
86
|
374 |
|
return $this->schema; |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Initializes the DB connection. |
91
|
|
|
* |
92
|
|
|
* This method is invoked right after the DB connection is established. |
93
|
|
|
* |
94
|
|
|
* The default implementation turns on `PDO::ATTR_EMULATE_PREPARES`. |
95
|
|
|
* |
96
|
|
|
* if {@see emulatePrepare} is true, and sets the database {@see charset} if it is not empty. |
97
|
|
|
* |
98
|
|
|
* It then triggers an {@see EVENT_AFTER_OPEN} event. |
99
|
|
|
*/ |
100
|
189 |
|
protected function initConnection(): void |
101
|
|
|
{ |
102
|
189 |
|
$this->pdo = $this->driver->createConnection(); |
103
|
189 |
|
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
104
|
|
|
|
105
|
189 |
|
if ($this->getEmulatePrepare() !== null && constant('PDO::ATTR_EMULATE_PREPARES')) { |
106
|
1 |
|
$this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->getEmulatePrepare()); |
107
|
|
|
} |
108
|
|
|
|
109
|
189 |
|
$charset = $this->driver->getCharset(); |
110
|
|
|
|
111
|
189 |
|
if ($charset !== null) { |
112
|
|
|
$this->pdo->exec('SET NAMES ' . $this->pdo->quote($charset)); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths