Can I assume PHP's time() and MySQL's NOW() will be the same?
I am creating an instance of an object and using an INSERT query on a
MySQL database at the same time. The table in the database has a field
called modified, which is automatically updated whenever the row is
inserted/changed.
When the constructor of my class is called, it sets the properties of the
object to be those used in the query. My question is, do I have to run a
SELECT query on my newly inserted/updated row to obtain its timestamp, or
can I safely assume that PHP's time() function would return the same
value?
For example:
<?php
// Inside the __construct method of a class
static::query('
INSERT INTO `table` (
`name`,
`content`
)
VALUES
(
"name",
"content"
);
');
// During insertion, `modified` column is set to NOW()
$this->name = 'name';
$this->content = 'content';
$this->modified = time();
// Can I count on this being reflected properly?
?>
There are only two possibilities I can think of that would negate this:
(1) the database is on a server with a different local time; (2) time
passes between the query and the call of the time() function (which I
seriously doubt would even make a difference of 1 second...).
Is it worth the expense of a SELECT query to get the updated time, or
should I stick with calling the time() function and risk that the next
time the row is selected, the modified value might be different than when
it was instantiated, in my application?
Thanks!
No comments:
Post a Comment