tags:

views:

40

answers:

3

I want to update the update_date field in oracle db.

I have two ways to do it. Which one is the better?

1.$now = date('Y-m-d H:i:s');

2.$now = "TO_CHAR(CURRENT_TIMESTAMP, 'YYYY-MM-DD HH24:MI:SS')";

+1  A: 

It depends if you want to rely on the time of the php-server or of the oracle-server.

eisberg
Thanks for your answer.
xdazzyy
+1  A: 

On version #1, PHP is responsible for the date formatting.

On version #2, this is Oracle

It's almost the same, provided that Y-m-d H:i:s is equivalent to YYYY-MM-DD HH24:MI:SS

If you are always setting the current date, I would say that you can do that on the DB side : it will save at least one concatenation.

$sql = 'UPDATE foo SET date = TO_CHAR(CURRENT_TIMESTAMP, "YYYY-MM-DD HH24:MI:SS")';
// VERSUS
$sql = 'UPDATE foo SET date = "' . date('Y-m-d H:i:s') . '"';
mexique1
Thanks for your answer.
xdazzyy
+1  A: 

In your second solution (2), you assume that 1) you database engine time is correct (correct timezone and so on), and 2) that you are using Oracle forever (otherwise, the SQL query might change).

If you use php (1), then you can make sure of that the time issues are solved from the code (performing check on the timezone etc...). Moreover, the query doesn't change even if you swtich ot another DB engine.

JSmaga
That's true ! ;)
mexique1