Skip to content

Commit 74363f4

Browse files
authored
Merge pull request #150 from tyrsson/fix-connection-doc
Update laminas/mezzio application integration doc.
2 parents 602d3ce + c0d6924 commit 74363f4

1 file changed

Lines changed: 41 additions & 35 deletions

File tree

‎docs/book/application-integration/usage-in-a-laminas-mvc-application.md‎

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,25 @@ For installation instructions, see [Installation](../index.md#installation).
55
## Configuration
66

77
The adapter factory is already wired into the service manager. You only
8-
need to provide the `db` configuration in `config/autoload/db.global.php`:
8+
need to provide the `AdapterInterface::class` configuration in `config/autoload/db.global.php`:
99

1010
```php title="config/autoload/db.global.php"
1111
<?php
1212

1313
declare(strict_types=1);
1414

15-
use PhpDb\Adapter\Driver\Pdo;
15+
use PhpDb\Adapter\AdapterInterface;
16+
use PhpDb\Mysql\Driver;
1617

1718
return [
18-
'db' => [
19-
'driver' => Pdo::class,
19+
AdapterInterface::class => [
20+
'driver' => Driver::class,
2021
'connection' => [
21-
'hostname' => (string) getenv('DB_HOSTNAME') ?: 'localhost',
22-
'username' => (string) getenv('DB_USERNAME'),
23-
'password' => (string) getenv('DB_PASSWORD'),
24-
'database' => (string) getenv('DB_DATABASE'),
25-
'port' => (string) getenv('DB_PORT') ?: '3306',
22+
'hostname' => 'localhost', // or use getenv('DB_HOSTNAME') for environment variable configuration
23+
'username' => 'your_username',
24+
'password' => 'your_password',
25+
'database' => 'your_database',
26+
'port' => '3306',
2627
'charset' => 'utf8',
2728
'driver_options' => [],
2829
],
@@ -43,19 +44,20 @@ separation), use named adapters:
4344

4445
declare(strict_types=1);
4546

46-
use PhpDb\Adapter\Driver\Pdo;
47+
use PhpDb\Adapter\AdapterInterface;
48+
use PhpDb\Mysql\Driver;
4749

4850
return [
49-
'db' => [
51+
AdapterInterface::class => [
5052
'adapters' => [
51-
'ReadAdapter' => [
52-
'driver' => Pdo::class,
53+
'ReadAdapter' => [
54+
'driver' => Driver::class,
5355
'connection' => [
54-
'hostname' => (string) getenv('DB_READ_HOSTNAME') ?: 'localhost',
55-
'username' => (string) getenv('DB_READ_USERNAME'),
56-
'password' => (string) getenv('DB_READ_PASSWORD'),
57-
'database' => (string) getenv('DB_READ_DATABASE'),
58-
'port' => (string) getenv('DB_READ_PORT') ?: '3306',
56+
'hostname' => 'localhost', // or use getenv('DB_READ_HOSTNAME') for environment variable configuration
57+
'username' => 'your_username',
58+
'password' => 'your_password',
59+
'database' => 'your_database',
60+
'port' => '3306',
5961
'charset' => 'utf8',
6062
'driver_options' => [],
6163
],
@@ -64,13 +66,13 @@ return [
6466
],
6567
],
6668
'WriteAdapter' => [
67-
'driver' => Pdo::class,
69+
'driver' => Driver::class,
6870
'connection' => [
69-
'hostname' => (string) getenv('DB_WRITE_HOSTNAME') ?: 'localhost',
70-
'username' => (string) getenv('DB_WRITE_USERNAME'),
71-
'password' => (string) getenv('DB_WRITE_PASSWORD'),
72-
'database' => (string) getenv('DB_WRITE_DATABASE'),
73-
'port' => (string) getenv('DB_WRITE_PORT') ?: '3306',
71+
'hostname' => 'localhost', // or use getenv('DB_WRITE_HOSTNAME') for environment variable configuration
72+
'username' => 'your_username',
73+
'password' => 'your_password',
74+
'database' => 'your_database',
75+
'port' => '3306',
7476
'charset' => 'utf8',
7577
'driver_options' => [],
7678
],
@@ -101,17 +103,21 @@ If you need to create an adapter without the container:
101103

102104
```php
103105
use PhpDb\Adapter\Adapter;
104-
use PhpDb\Mysql\Driver\Mysql;
105-
use PhpDb\Mysql\Platform\Mysql as MysqlPlatform;
106-
107-
$driver = new Mysql([
108-
'hostname' => 'localhost',
109-
'database' => 'my_database',
110-
'username' => 'my_username',
111-
'password' => 'my_password',
112-
]);
113-
114-
$adapter = new Adapter($driver, new MysqlPlatform());
106+
use PhpDb\Mysql\Connection;
107+
use PhpDb\Mysql\Driver;
108+
use PhpDb\Mysql\AdapterPlatform;
109+
110+
$adapter = new Adapter(
111+
new Driver(
112+
new Connection([
113+
'hostname' => 'localhost',
114+
'database' => 'my_database',
115+
'username' => 'my_username',
116+
'password' => 'my_password',
117+
]),
118+
new AdapterPlatform()
119+
)
120+
);
115121
```
116122

117123
You can read more about the

0 commit comments

Comments
 (0)