O
O
ozornick2021-06-19 10:22:49
PHP
ozornick, 2021-06-19 10:22:49

How to convert fetch_class to a string in PDO to the required type for the class?

$stmt = $pdo->prepare('SELECT * FROM user LIMIT 10');
$stmt->execute();
$sub = $stmt->fetchAll(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, User::class);
// User
private int       $id;
private string  $email;
private \DateTimeInterface $created_at;

How and where to convert string 12-06-2021 to Datetime? There is also a setDate(\DateTimeInterface $created_at) setter.
I want to use typing, but PDO knows little about it. Preferably without cumbersome code, perhaps there are parameters from the docks
UPD As I understand it, PDO ignores __set() and directly assigns values

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question