Re: Re: DB / tablevalues / query 'now()'
| From: | Daniel Convissor | Date: | Sun, 19 Dec 2004 23:00:21 +0000 |
| Subject: | Re: Re: DB / tablevalues / query 'now()' | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-16330@lists.php.net to get a copy of this message | ||
> Matthew Weier O'Phinney wrote:
> >* Stephan Heller <heller@daik.de>:
> >
> >>I'm looking for a possibility to insert a datetime-Value comparable to
> >>'now()' in MySql
> >>using 'autoPrepare' and 'execute'
> >>Now() doesn't work by using this methods
> >
> >You can use NOW() when using simply prepare() and execute():
> > $sth = $db->prepare('INSERT INTO table(ts) VALUES(!)');
> > $res = $db->execute($sth, array('NOW()'));
The best approach is putting the NOW() call in the prepared SQL statement
because it never changes and it's a function. Example:
$sth = $db->prepare('INSERT INTO table (ch, ts) VALUES (?, NOW())');
Personally, I don't like autoPrepare(). Too much magic. I like SQL.
It's powerful. Use it.
As far as abstracting the function used to obtain the present time, as
someone was asking about, that kind of stuff may come up in Version 2 of
DB.
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409