Skip to content

Commit

Permalink
Improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Jun 1, 2024
1 parent 65018f0 commit 15eae3d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,43 @@ But this also works in a composer setup.

## How to use

### Connect to an existing PDO connection

```php
<?php
declare(strict_types = 1);

use SimplePhpModelSystem\Database;

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

$db = new Database(null);
// With Symfony: EntityManagerInterface $em
$db->setConnection($em->getConnection()->getNativeConnection());// Wants a PDO connection object class
```

### Connect with config

```php
<?php
declare(strict_types = 1);

use SimplePhpModelSystem\Database;
use examples\User;

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

$configFile = __DIR__ . DIRECTORY_SEPARATOR . 'config.php';// Copy config.dist.php and fill the values
$config = require $configFile;
$db = new Database($config);
$db->connect();// Will throw an exception if not successfull
```

### Manage models

```php
<?php

use examples\User;

// Without models

Expand Down

0 comments on commit 15eae3d

Please sign in to comment.