473,505 Members | 14,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Database query failing when called from php front end

23 New Member
Hello All,
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
  1. <?php
  2. $database = 'abc';
  3. $user = 'xxx';
  4. $password = 'xxx';
  5.  
  6. $conn = db2_connect($database, $user, $password);
  7.  
  8.  
  9. if ($conn) {
  10.     echo "Connection succeeded.";
  11.     $qh ="select {fn TIMESTAMPDIFF(DAY,timestamp('1970-01-01-00.00.00'),current_timestamp)} as \"t1\" from sysibm.sysdummy1";
  12.  
  13.     $result = db2_exec($conn, $qh);
  14.     while($row=db2_fetch_array($result)){
  15.     $v=$row[0];
  16.     echo $v;
  17.     }
  18.  
  19.    db2_close($conn);
  20. }
  21. else {
  22.     echo "Connection failed.";
  23. }
  24. ?>
  25.  
  26.  
Basically, the db2_exec statement fails when I run this php file.
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.
Jun 2 '10 #1
6 3533
Dormilich
8,658 Recognized Expert Moderator Expert
can you get anything out of db2_stmt_errormsg()? (I’d prefer to use PDO, since that throws Exception … but that’s another story)
Jun 2 '10 #2
knellim
23 New Member
@Dormilich
Hey,
I am still stuck with the same problem. The error mesage is:
[IBM][CLI Driver][Apache Derby] Column 'DAY' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'DAY' is not a column in the target table. SQLCODE=-1

Has anyone tried to use PHP with derby database. I think PHP is unable to recognize the fn keyword(its a jdbc escape sequence). Do I need to add anythin to php for jdbc functions to be supported?
Please advise!
Jun 28 '10 #3
JKing
1,206 Recognized Expert Top Contributor
@knellim
You mention this as being the equivalent:
select {fn TIMESTAMPDIFF( SQL_TSI_day, timestamp('1970-01-01-00.00.00'),current_timestamp)

But you use the word DAY in place of the keyword SQL_TSI_day

Try switching that around.
Expand|Select|Wrap|Line Numbers
  1.     $qh ="select {fn TIMESTAMPDIFF(SQL_TSI_DAY,timestamp('1970-01-01-00.00.00'),current_timestamp)} as \"t1\" from sysibm.sysdummy1";
  2.  
Jun 28 '10 #4
knellim
23 New Member
@JKing
I actually tried that as well.. but it does not work. The fact is I am able to get values when I run it from the derby command prompt ij. But when i give this query from php it throws me an error.

Just for information, I am using php 5 and i am connecting php and derby using db2 runtime client and ibm_db2 driver.
Jun 28 '10 #5
JKing
1,206 Recognized Expert Top Contributor
Do you get the same error using SQL_TSI_DAY?

From the error message you provided earlier it seems to me that it is interpreting the word day as a column name.

I also checked the documentation on the TIMESTAMPDIFF in the derby reference manual and this is what it says:

Valid intervals for TIMESTAMPADD and TIMESTAMPDIFF
The TIMESTAMPADD and TIMESTAMPDIFF functions are used to perform arithmetic
with timestamps. These two functions use the following valid intervals for arithmetic
operations:
• SQL_TSI_DAY
• SQL_TSI_FRAC_SECOND
• SQL_TSI_HOUR
• SQL_TSI_MINUTE
• SQL_TSI_MONTH
• SQL_TSI_QUARTER
• SQL_TSI_SECOND
• SQL_TSI_WEEK
• SQL_TSI_YEAR

If you don't mind switching it around and posting the error message it could be helpful.
Jun 28 '10 #6
knellim
23 New Member
@JKing
Sure..Here is the code i ran:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $database = 'XYZ';
  3. $user = 'vXXX';
  4. $password = 'QQQQQ';
  5.  
  6. $conn = db2_connect($database, $user, $password);
  7.  
  8.  
  9. if ($conn) {
  10.     echo "Connection succeeded.";
  11.     $query="select {fn timestampadd(SQL_TSI_SECOND,30,end1)} from request";
  12.  
  13.     $result = db2_prepare($conn, $query);
  14.  
  15.    if ($result) {
  16.     print "Successfully prepared the table.\n";
  17.     $resultfinal=db2_execute($result);
  18.     echo $resultfinal;
  19.    }
  20.    if ($resultfinal){
  21.    $val=db2_fetch_row($resultfinal);
  22.    $val1=$val[0];
  23.   print $val1;
  24. }
  25.    else
  26.    echo db2_stmt_errormsg();
  27. }else {
  28.     echo "Connection failed.";
  29. }
  30. ?>
  31.  
  32.  
The output with error mesage when i run it is:
Connection succeeded.Successfully prepared the table.
PHP Warning: db2_execute(): Statement Execute Failed in /var/www/html/testquery.php on line 17

Warning: db2_execute(): Statement Execute Failed in /var/www/html/testquery.php on line 17
[IBM][CLI Driver][Apache Derby] Column 'SQL_TSI_SECOND' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'SQL_TSI_SECOND' is not a column in the target table. SQLCODE=-1
Jun 28 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1437
by: Santosh | last post by:
Hi, I have a script running which fails when it tries to execute an Update query, but when i try to run the query from the SQLQueryAnalyzer it runs fine. Can somebody try and explain this...
2
1994
by: Gershon | last post by:
I have an ASP.NET/C# web application running against a SQL Server database using ADO.NET. Whenever there is a long-running database query, the web application hangs until the database query is...
3
1205
by: Rob Venable | last post by:
Hi everyone, Can anyone see a problem with this code. I'm kinda new to asp.net and I'm having a problem populating a drop down list with a database query. The results of my query populate the list...
2
1401
by: Mejmeyster | last post by:
Hi Everyone! I've been desperately trying to prepare a database query from Access to Excel. The problem is, when I ask MS Query to import data from more than one table, no data is importing, only...
0
1190
by: simba | last post by:
Hello, I am having trouble executing more than one database query in a JSP page. The first query executes fine but it seems to skip by the second one. Any ideas why? Thanks
5
5679
by: Eglute | last post by:
Hello I want to show the results of database query in Visual basic. Do you know how to do this? I want to show the results in objects such as label or text box. Please help me. My code is: Dim db...
1
1840
by: Eglute | last post by:
Hello I want to show the results of MS Access database query in Visual basic. Do you know how to do this? I want to show the results in objects such as label or text box. Please help me. My code is:...
1
7840
by: jesmi | last post by:
my code is: U]employee.cfm <html> <head> <title>Employee List</title> </head> <body> <h1>Employee List</h1>
1
1925
by: obrienkev | last post by:
Hi, I want to mark the CheckListBox items as Checked based on a database query. So the CheckListBox items should be checked if each item matches fundsAffected field from the below query... ...
7
1511
by: Brent | last post by:
Page1.aspx calls Page2.aspx like this: ---------------- Server.Execute("Page2.aspx"); --------------- Page2.aspx's Page_Load event calls a function, getMsgs().This function runs normally...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.