I am using PHP to connect to derby/db2 database.
I want to implement unix_timestamp() function (used in mysql) to its equivalent in derby database.
I found the equivalent as
select {fn TIMESTAMPDIFF( SQL_TSI_day, timestamp('1970-01-01-00.00.00'),current_timestamp)} as "t1" from sysibm.sysdummy1;
So as a test, I wrote a small php program to check if i am getting the results. Its as shown below
Expand|Select|Wrap|Line Numbers
- <?php
- $database = 'abc';
- $user = 'xxx';
- $password = 'xxx';
- $conn = db2_connect($database, $user, $password);
- if ($conn) {
- echo "Connection succeeded.";
- $qh ="select {fn TIMESTAMPDIFF(DAY,timestamp('1970-01-01-00.00.00'),current_timestamp)} as \"t1\" from sysibm.sysdummy1";
- $result = db2_exec($conn, $qh);
- while($row=db2_fetch_array($result)){
- $v=$row[0];
- echo $v;
- }
- db2_close($conn);
- }
- else {
- echo "Connection failed.";
- }
- ?>
When I run the sql statement separately from derby prompt , it shows me the answer.
Please provide me any input as to why is it failing.