Reputation: 119
I want to show in my page that the database they were looking at was last modified on a certain date & time. I have the following code for that:
$lastUpdate = $pdo->prepare("SELECT lastUpdate FROM bng WHERE lastUpdate IN
(SELECT max(lastUpdate) FROM bng)");
$lastUpdate->execute();
As I mentioned in the title, I want to echo the result on my page, I tried:
<?php
echo '<p>Database Last Modified on '.date("l, d F Y - h:i:s A",strtotime($lastUpdate)).'</p>';
?>
but it gives me the wrong data and an error message
Warning: strtotime() expects parameter 1 to be string,
Hope this question makes sense. Thanks in advance.
Upvotes: 3
Views: 143
Reputation: 3079
It is working fine check your variable $lastUpdate
and change that date into string
echo '<p>Database Last Modified on '.date("l, d F Y - h:i:s A",strtotime("1-1-2017")).'</p>';
Fetch Query from database check this link
Upvotes: 0
Reputation: 781726
$lastUpdate
is a PDO statement, not the value from the database. You need to call fetch()
and then extract the value from the row.
$lastUpdate = $pdo->prepare("SELECT max(lastUpdate) AS lastUpdate FROM bng");
$lastUpdate->execute();
$row = $lastUpdate->fetch(PDO::FETCH_ASSOC);
echo '<p>Database Last Modified on '.date("l, d F Y - h:i:s A",strtotime($row['lastUpdate'])).'</p>';
Upvotes: 1