For example I use this to insert in table:
INSERT INTO `mytable` (`name`, `type`, `date`) VALUES ('Smit', 12, now());
Then I need get all or some rows from this table:
$st = $db->prepare("SELECT * FROM `mytable` WHERE id=:id");
$st->bindParam(':id', $id, PDO::PARAM_INT);
$st->execute();
$result = $st->fetchAll(PDO::FETCH_ASSOC);
Where I receive $result[0]['date']
as string = "2016-09-10 21:00:00"
. Maybe PDO has some PDO::PARAM_
which can set all date fields to timestamp?
P.S. Yes I know about php strtotime()
which I can use here, but in this case we do double conversion. I mean, if I understood this right, MySQL save datetime as unix timestamp and when we get it as string, then convert again to a timestamp, and it is not a good solution.