-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-class.php
More file actions
35 lines (26 loc) · 852 Bytes
/
create-class.php
File metadata and controls
35 lines (26 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
use Alura\Pdo\Domain\Model\Student;
use Alura\Pdo\Infrastructure\Persistence\ConnectionCreator;
use Alura\Pdo\Infrastructure\Repository\PdoStudentRepository;
require_once 'vendor/autoload.php';
$connection = ConnectionCreator::createConnection();
$studentRepository = new PdoStudentRepository($connection);
$connection->beginTransaction();
try {
$aStudent = new Student(
id: null,
name: 'Alfredo Fredo',
birthDate: new DateTimeImmutable('2002-04-23')
);
$studentRepository->save($aStudent);
$anotherStudent = new Student(
id: null,
name: 'Amélia Mélia',
birthDate: new DateTimeImmutable('2002-06-12')
);
$studentRepository->save($anotherStudent);
$connection->commit();
} catch (PDOException $e) {
echo $e->getMessage();
$connection->rollBack();
}