PDO: How to fetch TIMESTAMP values?
| From: | Michael Phillipson | Date: | Tue, 24 Jan 2006 21:45:48 +0000 |
| Subject: | PDO: How to fetch TIMESTAMP values? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-229188@lists.php.net to get a copy of this message | ||
I recently began evaluating the feasibility of reworking our current
database access framework, which utilizes the PHP-native drivers for our
database (Interbase), to one which makes use of the PDO extension.
Unfortunately, I quickly hit a roadblock.
I have tried every permutation available in the PDO documentation, as far as
I can see, in order to retrieve the value of a TIMESTAMP-type field from a
given table, but so far I have been unsuccessful.
Using the PHP-native functions for Interbase, I used to be able to
accomplish this with the following code:
<?php
$sql = "SELECT TIMESTAMP_FIELD FROM MY_TABLE";
$result = ibase_query($dbh, $sql);
$row = ibase_fetch_row($result, IBASE_UNIXTIME);
$field = $row[0];
echo "$field";
?>
Here is one of the many [failed] methods I have attempted using a PDO:
<?php
$sql = "SELECT TIMESTAMP_FIELD FROM MY_TABLE";
$row = $dbh->query($sql);
$field = $row['TIMESTAMP_FIELD'];
echo "$field";
?>
In the first instance, a numeric (integer) value would be displayed on the
screen. In the PDO example, nothing is displayed.
I have also tried rewriting the PDO code above as a prepared statement, but
i get the same result.
Has anyone else bumped up against problems with TIMESTAMP fields when using
the Interbase PDO driver or some other? Any suggestions would be
appreciated. Thanks!