Skip to content

Commit 15eae3d

Browse files
committed
Improve docs
1 parent 65018f0 commit 15eae3d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,43 @@ But this also works in a composer setup.
1919

2020
## How to use
2121

22+
### Connect to an existing PDO connection
23+
2224
```php
2325
<?php
26+
declare(strict_types = 1);
27+
28+
use SimplePhpModelSystem\Database;
29+
30+
require_once __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';// Use your autoloader or require classes by hand
31+
32+
$db = new Database(null);
33+
// With Symfony: EntityManagerInterface $em
34+
$db->setConnection($em->getConnection()->getNativeConnection());// Wants a PDO connection object class
35+
```
2436

37+
### Connect with config
38+
39+
```php
40+
<?php
2541
declare(strict_types = 1);
2642

2743
use SimplePhpModelSystem\Database;
28-
use examples\User;
2944

3045
require_once __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';// Use your autoloader or require classes by hand
3146

3247
$configFile = __DIR__ . DIRECTORY_SEPARATOR . 'config.php';// Copy config.dist.php and fill the values
3348
$config = require $configFile;
3449
$db = new Database($config);
3550
$db->connect();// Will throw an exception if not successfull
51+
```
52+
53+
### Manage models
54+
55+
```php
56+
<?php
57+
58+
use examples\User;
3659

3760
// Without models
3861

0 commit comments

Comments
 (0)