Re: DB / tablevalues / query 'now()'
| From: | Matthew Weier O'Phinney | Date: | Sat, 18 Dec 2004 19:23:36 +0000 |
| Subject: | Re: DB / tablevalues / query 'now()' | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-16317@lists.php.net to get a copy of this message | ||
* 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()'));
However, this doesn't work with autoPrepare() -- since, from my
experience with DB (haven't delved into the code much), it uses the ?
placeholder in all instances, not the ! (literal) placeholder.
To do something similar with autoPrepare(), you'll need to build your
timestamp by hand -- which, unfortunately, means you'll possibly break
database portability. One such solution would be:
$params = array('ts');
$sth = $db->autoPrepare('table', $params, DB_AUTOQUERY_INSERT);
$res = $db->autoExecute($sth, array(date('Y-m-d H:i:s')));
This should work with a variety of RDBMS, but it may cause issues with
others.
--
Matthew Weier O'Phinney | mailto:matthew@garden.org
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org