how can i create a mysql sql statement to insert a php 'time()' into mysql?

i've got the mysql var 't1, timestamp' but i can't figure out how to do an
insert

$q = time();
$sql = sprintf("insert into foo (id, ctime) values(%d, %???), $id, $q);

can't figure out how to get this to work...

if i create a sql statement and run it directly within mysql,

-->insert into foo (id, ctime) values(2, NOW());

this works.. but i can't figure out how to create the sql using the php
time() function and getting the insert from the php app...

so what's the basic part i'm missing??!!

-bruce




-----Original Message-----
From: Silvio Porcellana [mailto:[EMAIL PROTECTED]
Sent: Monday, September 26, 2005 8:51 AM
To: php-general@lists.php.net
Subject: Re: [PHP] mysql/php date functions..


Jim Moseby wrote:
>
> Hi Bruce!
>
> MySQL and PHP both have extensive built-in date functions that are clearly
> documented and extraordinarily easy to use. For the vast majority of
> situations, there is no need to manually write any custom date-handling
> code. The decision to use MySQL or PHP to manipulate a date for a given
> instance depends largely on the particulars of that situation.
>
> For instance, if you want to increment a MySQL date column by one day, it
> would likely be better to use the MySQL date functions to do it, because
to
> use PHP, you have to read the date, manipulate it, then write it back,
> whereas if you use a SQL statement, you can do it with one DB call.
>
> See:
> http://www.php.net/datetime
> http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html
>
> Cheers!
>

Just my 0.02 euros.

When I need to use dates in PHP *and* MySQL I usually use the UNIX
timestamp (seconds since the epoch, that is, the PHP http://php.net/time
output).
This way I can (quite) easily calculate date differences etc. (usually
all the calculations are done in PHP, also when building SQL queries).

As I said, just my 0.02 euros...

Cheers
Silvio

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to