Skip to content

Commit cadc5f4

Browse files
committed
Fix deprecated PDO::MYSQL_ATTR_INIT_COMMAND
1 parent ec6a8e0 commit cadc5f4

14 files changed

Lines changed: 89 additions & 19 deletions

File tree

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ You can use 'db' (with _Laminas\Db_) config or 'doctrine' (with _DoctrineORMModu
6464
```php
6565
<?php
6666
// config/autoload/local.php
67+
68+
$pdoMysqlInitCommandAttr = defined('Pdo\\Mysql::ATTR_INIT_COMMAND')
69+
? constant('Pdo\\Mysql::ATTR_INIT_COMMAND')
70+
: \PDO::MYSQL_ATTR_INIT_COMMAND;
71+
6772
return [
6873
'db' => [
6974
'username' => 'mysqluser',
@@ -72,7 +77,7 @@ return [
7277
'database' => 'mysqldbname',
7378
'host' => 'mysqlhost',
7479
'driver_options' => [
75-
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'',
80+
$pdoMysqlInitCommandAttr => 'SET NAMES \'UTF8\'',
7681
],
7782
],
7883
];
@@ -83,6 +88,11 @@ return [
8388
```php
8489
<?php
8590
// config/autoload/local.php
91+
92+
$pdoMysqlInitCommandAttr = defined('Pdo\\Mysql::ATTR_INIT_COMMAND')
93+
? constant('Pdo\\Mysql::ATTR_INIT_COMMAND')
94+
: \PDO::MYSQL_ATTR_INIT_COMMAND;
95+
8696
return [
8797
'doctrine' => [
8898
'connection' => [
@@ -95,7 +105,7 @@ return [
95105
'host' => 'mysqlhost',
96106
'port' => '3306',
97107
'driverOptions' => [
98-
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'',
108+
$pdoMysqlInitCommandAttr => 'SET NAMES \'UTF8\'',
99109
],
100110
],
101111
],

spec/Fixture/config/autoload-for-cannot-connect-to-db/error-hero-module.local.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
use Laminas\Mail\Transport\InMemory;
66
use Laminas\ServiceManager\Factory\InvokableFactory;
77

8+
$pdoMysqlInitCommandAttr = defined('Pdo\\Mysql::ATTR_INIT_COMMAND')
9+
? \Pdo\Mysql::ATTR_INIT_COMMAND
10+
: \PDO::MYSQL_ATTR_INIT_COMMAND;
11+
812
return [
913

1014
'service_manager' => [
@@ -20,7 +24,7 @@
2024
'driver' => 'Pdo',
2125
'dsn' => 'mysql:dbname=errorheromodule;host=127.0.0.1',
2226
'driver_options' => [
23-
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
27+
$pdoMysqlInitCommandAttr => "SET NAMES 'UTF8'",
2428
],
2529
],
2630

spec/Fixture/config/autoload-for-enable-display-errors/error-hero-module.local.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
use Laminas\Mail\Transport\InMemory;
66
use Laminas\ServiceManager\Factory\InvokableFactory;
77

8+
$pdoMysqlInitCommandAttr = defined('Pdo\\Mysql::ATTR_INIT_COMMAND')
9+
? \Pdo\Mysql::ATTR_INIT_COMMAND
10+
: \PDO::MYSQL_ATTR_INIT_COMMAND;
11+
812
return [
913

1014
'service_manager' => [
@@ -20,7 +24,7 @@
2024
'driver' => 'Pdo',
2125
'dsn' => 'mysql:dbname=errorheromodule;host=127.0.0.1',
2226
'driver_options' => [
23-
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
27+
$pdoMysqlInitCommandAttr => "SET NAMES 'UTF8'",
2428
],
2529
],
2630

spec/Fixture/config/autoload-for-specific-error-and-exception/error-hero-module.local.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
use Laminas\Db\Adapter\AdapterInterface;
44

5+
$pdoMysqlInitCommandAttr = defined('Pdo\\Mysql::ATTR_INIT_COMMAND')
6+
? \Pdo\Mysql::ATTR_INIT_COMMAND
7+
: \PDO::MYSQL_ATTR_INIT_COMMAND;
8+
59
return [
610

711
'db' => [
@@ -10,7 +14,7 @@
1014
'driver' => 'Pdo',
1115
'dsn' => 'mysql:dbname=errorheromodule;host=127.0.0.1',
1216
'driver_options' => [
13-
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
17+
$pdoMysqlInitCommandAttr => "SET NAMES 'UTF8'",
1418
],
1519
],
1620

spec/Fixture/config/autoload-for-xmlhttprequest-with-non-json-message/error-hero-module.local.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
use Laminas\Db\Adapter\AdapterInterface;
44

5+
$pdoMysqlInitCommandAttr = defined('Pdo\\Mysql::ATTR_INIT_COMMAND')
6+
? \Pdo\Mysql::ATTR_INIT_COMMAND
7+
: \PDO::MYSQL_ATTR_INIT_COMMAND;
8+
59
return [
610

711
'db' => [
@@ -10,7 +14,7 @@
1014
'driver' => 'Pdo',
1115
'dsn' => 'mysql:dbname=errorheromodule;host=127.0.0.1',
1216
'driver_options' => [
13-
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
17+
$pdoMysqlInitCommandAttr => "SET NAMES 'UTF8'",
1418
],
1519
],
1620

spec/Fixture/config/autoload-for-xmlhttprequest/error-hero-module.local.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
use Laminas\Db\Adapter\AdapterInterface;
44

5+
$pdoMysqlInitCommandAttr = defined('Pdo\\Mysql::ATTR_INIT_COMMAND')
6+
? \Pdo\Mysql::ATTR_INIT_COMMAND
7+
: \PDO::MYSQL_ATTR_INIT_COMMAND;
8+
59
return [
610

711
'db' => [
@@ -10,7 +14,7 @@
1014
'driver' => 'Pdo',
1115
'dsn' => 'mysql:dbname=errorheromodule;host=127.0.0.1',
1216
'driver_options' => [
13-
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
17+
$pdoMysqlInitCommandAttr => "SET NAMES 'UTF8'",
1418
],
1519
],
1620

spec/Fixture/config/autoload-with-doctrine/error-hero-module.local.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
use Doctrine\DBAL\Driver\PDO\MySql\Driver;
44
use Laminas\Db\Adapter\AdapterInterface;
55

6+
$pdoMysqlInitCommandAttr = defined('Pdo\\Mysql::ATTR_INIT_COMMAND')
7+
? \Pdo\Mysql::ATTR_INIT_COMMAND
8+
: \PDO::MYSQL_ATTR_INIT_COMMAND;
9+
610
return [
711

812
'doctrine' => [
@@ -16,7 +20,7 @@
1620
'host' => '127.0.0.1',
1721
'port' => '3306',
1822
'driverOptions' => [
19-
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
23+
$pdoMysqlInitCommandAttr => "SET NAMES 'UTF8'",
2024
],
2125
],
2226
],

spec/Fixture/config/autoload-with-enable-sendmail-with-empty-email-receivers/error-hero-module.local.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
use Laminas\Mail\Transport\InMemory;
66
use Laminas\ServiceManager\Factory\InvokableFactory;
77

8+
$pdoMysqlInitCommandAttr = defined('Pdo\\Mysql::ATTR_INIT_COMMAND')
9+
? \Pdo\Mysql::ATTR_INIT_COMMAND
10+
: \PDO::MYSQL_ATTR_INIT_COMMAND;
11+
812
return [
913

1014
'service_manager' => [
@@ -20,7 +24,7 @@
2024
'driver' => 'Pdo',
2125
'dsn' => 'mysql:dbname=errorheromodule;host=127.0.0.1',
2226
'driver_options' => [
23-
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
27+
$pdoMysqlInitCommandAttr => "SET NAMES 'UTF8'",
2428
],
2529
],
2630

spec/Fixture/config/autoload-with-enable-sendmail/error-hero-module.local.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
use Laminas\Mail\Transport\InMemory;
66
use Laminas\ServiceManager\Factory\InvokableFactory;
77

8+
$pdoMysqlInitCommandAttr = defined('Pdo\\Mysql::ATTR_INIT_COMMAND')
9+
? \Pdo\Mysql::ATTR_INIT_COMMAND
10+
: \PDO::MYSQL_ATTR_INIT_COMMAND;
11+
812
return [
913

1014
'service_manager' => [
@@ -20,7 +24,7 @@
2024
'driver' => 'Pdo',
2125
'dsn' => 'mysql:dbname=errorheromodule;host=127.0.0.1',
2226
'driver_options' => [
23-
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
27+
$pdoMysqlInitCommandAttr => "SET NAMES 'UTF8'",
2428
],
2529
],
2630

spec/Fixture/config/autoload/error-hero-module.local.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
use PDO;
66
use Laminas\Db\Adapter\AdapterInterface;
7+
8+
$pdoMysqlInitCommandAttr = defined('Pdo\\Mysql::ATTR_INIT_COMMAND')
9+
? \Pdo\Mysql::ATTR_INIT_COMMAND
10+
: PDO::MYSQL_ATTR_INIT_COMMAND;
711
return [
812

913
'db' => [
@@ -12,7 +16,7 @@
1216
'driver' => 'Pdo',
1317
'dsn' => 'mysql:dbname=errorheromodule;host=127.0.0.1',
1418
'driver_options' => [
15-
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
19+
$pdoMysqlInitCommandAttr => "SET NAMES 'UTF8'",
1620
],
1721
],
1822

0 commit comments

Comments
 (0)