File tree 1 file changed +24
-1
lines changed
1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -19,20 +19,43 @@ But this also works in a composer setup.
19
19
20
20
## How to use
21
21
22
+ ### Connect to an existing PDO connection
23
+
22
24
``` php
23
25
<?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
+ ```
24
36
37
+ ### Connect with config
38
+
39
+ ``` php
40
+ <?php
25
41
declare(strict_types = 1);
26
42
27
43
use SimplePhpModelSystem\Database;
28
- use examples\User;
29
44
30
45
require_once __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';// Use your autoloader or require classes by hand
31
46
32
47
$configFile = __DIR__ . DIRECTORY_SEPARATOR . 'config.php';// Copy config.dist.php and fill the values
33
48
$config = require $configFile;
34
49
$db = new Database($config);
35
50
$db->connect();// Will throw an exception if not successfull
51
+ ```
52
+
53
+ ### Manage models
54
+
55
+ ``` php
56
+ <?php
57
+
58
+ use examples\User;
36
59
37
60
// Without models
38
61
You can’t perform that action at this time.
0 commit comments