Re: Re: DB / tablevalues / query 'now()'

From: Date: Sun, 19 Dec 2004 11:12:23 +0000
Subject: Re: Re: DB / tablevalues / query 'now()'
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-16323@lists.php.net to get a copy of this message
Hi Daniel and DB fans, 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()')); 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. Why is the DB_Common not providing a now() method for that ?
Basic could return 'NOW()' A peculiar implementations not having this feature could return another values as e.g. 'TIMESTAMP("NOW")'. As it's sometimes not something static, I mean a methode now() rather as a property (see Matthew's example above) I ignore in wich extend the prepare/execute stuff can handle that ;) It should not break BC, could wait a little that each major implementations furnish their version if different of the basic 'NOW()' Hope to be understable and not out of subject Best -- bertrand Gugger (toggg)

« previous php.pear.general (#16323) next »