Skip to content

Commit db9466b

Browse files
authored
Merge pull request #98 from clue-labs/urlencode
Documentation for URL-encoding special characters in credentials
2 parents 6dae976 + ec48eb4 commit db9466b

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ authentication, port and database to connect to:
132132
$factory->createConnection('user:secret@localhost:3306/database');
133133
```
134134

135+
Note that both the username and password must be URL-encoded (percent-encoded)
136+
if they contain special characters:
137+
138+
```php
139+
$user = 'he:llo';
140+
$pass = 'p@ss';
141+
142+
$promise = $factory->createConnection(
143+
rawurlencode($user) . ':' . rawurlencode($pass) . '@localhost:3306/db'
144+
);
145+
```
146+
135147
You can omit the port if you're connecting to default port `3306`:
136148

137149
```php
@@ -213,6 +225,18 @@ authentication, port and database to connect to:
213225
$factory->createLazyConnection('user:secret@localhost:3306/database');
214226
```
215227

228+
Note that both the username and password must be URL-encoded (percent-encoded)
229+
if they contain special characters:
230+
231+
```php
232+
$user = 'he:llo';
233+
$pass = 'p@ss';
234+
235+
$connection = $factory->createLazyConnection(
236+
rawurlencode($user) . ':' . rawurlencode($pass) . '@localhost:3306/db'
237+
);
238+
```
239+
216240
You can omit the port if you're connecting to default port `3306`:
217241

218242
```php
@@ -501,7 +525,7 @@ For example, to create an empty test database, you can also use a temporary
501525
```bash
502526
$ docker run -it --rm --net=host \
503527
-e MYSQL_RANDOM_ROOT_PASSWORD=yes -e MYSQL_DATABASE=test \
504-
-e MYSQL_USER=test -e MYSQL_PASSWORD=test mysql
528+
-e MYSQL_USER=test -e MYSQL_PASSWORD=test mysql:5
505529
```
506530

507531
To run the test suite, go to the project root and run:

src/Factory.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ public function __construct(LoopInterface $loop, ConnectorInterface $connector =
103103
* $factory->createConnection('user:secret@localhost:3306/database');
104104
* ```
105105
*
106+
* Note that both the username and password must be URL-encoded (percent-encoded)
107+
* if they contain special characters:
108+
*
109+
* ```php
110+
* $user = 'he:llo';
111+
* $pass = 'p@ss';
112+
*
113+
* $promise = $factory->createConnection(
114+
* rawurlencode($user) . ':' . rawurlencode($pass) . '@localhost:3306/db'
115+
* );
116+
* ```
117+
*
106118
* You can omit the port if you're connecting to default port `3306`:
107119
*
108120
* ```php
@@ -252,6 +264,18 @@ public function createConnection($uri)
252264
* $factory->createLazyConnection('user:secret@localhost:3306/database');
253265
* ```
254266
*
267+
* Note that both the username and password must be URL-encoded (percent-encoded)
268+
* if they contain special characters:
269+
*
270+
* ```php
271+
* $user = 'he:llo';
272+
* $pass = 'p@ss';
273+
*
274+
* $connection = $factory->createLazyConnection(
275+
* rawurlencode($user) . ':' . rawurlencode($pass) . '@localhost:3306/db'
276+
* );
277+
* ```
278+
*
255279
* You can omit the port if you're connecting to default port `3306`:
256280
*
257281
* ```php

0 commit comments

Comments
 (0)