473,387 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PHP odbc error,with no error

6
hello all experts,


basically, i have a very small project, in which 97% of the work is complete. yet there is an issue which i cannot solve and i have no error to indicate what the problem is.Perhaps, in this case, it might just be a bad thing

I have 2 webpages, one with a datepicker in jscript with an id/name ="calendar";
this passes its value back into a textbox which is then submitted to the second webpage(database driven- mssql)... the variable $ts holds the passed value.

$ts then forms part of an mssql query which is then used to search the database and a result is supposed to be outputted.

however, the result variable only holds 'resource id#4' and no data is displayed and output to the screen from the database even though there should be matching records.... BUT when i have a simple static select statement, we recieve output to the page.
i have some code below.

CALENDAR PAGE::
Expand|Select|Wrap|Line Numbers
  1. <form name="tstest" method="GET" action = "printTrial.php">
  2.     <input type="text" id="calendar" name="calendar" />
  3.     <button id="trigger">...</button>
  4.  
  5. PRINTTRIAL.PHP::
  6.  
  7. $ts = $_GET['calendar'];
  8.  
  9. $stamp = "select stamp from dates where stamp < '" & ts & "'";
  10. $result = odbc_exec($connect,$stamp);
  11.  
  12. if(odbc_num_rows($result) == 0)
  13.     {
  14.         echo 'no rows that match';
  15.     }
  16.     else
  17.     {
  18.         echo ' there are matching records';
  19.     }
  20. // this returns '' there are matching records';
  21.  
  22.     if (odbc_next_result($result)){
  23. while ($rs = odbc_fetch_array($result))
  24. {
  25. echo $rs. ' this is $rs';
  26.   $compname=odbc_result($rs,"stamp");
  27.  
  28.   echo "<td><p>$compname[stamp]</td></tr>";
  29. }
  30. }
  31. odbc_close($connect);
  32.  
when i change the stamp variable to $stamp = "select stamp from dates where stamp < $ts";then i get the error
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][SQL Native Client][SQL Server]Executing SQL directly; no cursor., SQL state 01000 in SQLExecDirect in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\printTrial.php on line 58

Warning: odbc_num_rows(): supplied argument is not a valid ODBC result resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\printTrial.php on line 60
no rows that match

Warning: odbc_next_result(): supplied argument is not a valid ODBC result resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\printTrial.php on line 69


but i suppose in reality that is only one error/warning, because they all follow suit.

PLEASE PLEASE PLEASE HELP!
thankyou very much for your time
please reply asap,it would bring me back to sanity(at the very least!)

P.S. THE ONLY THING I CAN THINK OF, IS A MATCH BETWEEN DATE FORMATS, WHERE THE SEPERATOR '-'HAS BEEN USED IN THE CALENDAR, I ALSO WHAT WHAT looks like!!!! a '-' in mssql tables... but i think this is also improbable.
can you also please tell me if u CANNOT HELP, atleast then i know people are trying to help!
imran
Feb 26 '08 #1
9 7516
ronverdonk
4,258 Expert 4TB
1. statement 9 has an error, you do not compare variable $ts but just ts; statement should be
Expand|Select|Wrap|Line Numbers
  1. $stamp = "select stamp from dates where stamp < '$ts'";
2. the result of the odbc_exec is either a FALSE indicator or a RESOURCE ID, just like it did. You have to access that resource id to get the resulting rows, using one of the many commands like odbc_fetch_array().

Ronald
Feb 26 '08 #2
2DIL
6
1. statement 9 has an error, you do not compare variable $ts but just ts; statement should be
Expand|Select|Wrap|Line Numbers
  1. $stamp = "select stamp from dates where stamp < '$ts'";
2. the result of the odbc_exec is either a FALSE indicator or a RESOURCE ID, just like it did. You have to access that resource id to get the resulting rows, using one of the many commands like odbc_fetch_array().

Ronald
hi again,
it still doesnt work.
i have listed my complete page code below:( i have changed the mssql query to $ts):

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // including connection file 
  3.  include ("connect.php");
  4.  
  5. //ini_set ( 'odbc.defaultlrl' , '65536' );
  6. $ts = $_GET['calendar']; //getting data from cal.php
  7.  
  8.  
  9. print '$_POST array';
  10. // ------------------------------------
  11. print "<BR/>"; 
  12. // ------------------------------------
  13. foreach ( $_POST as $key => $value ) {
  14.  print $key . " " . "=" . " " . $value;
  15.  print "<BR/>";
  16. }
  17. // ------------------------------------
  18. print "<BR/>";
  19. // ------------------------------------
  20. print "<BR/>";
  21. // ------------------------------------
  22. print '$_GET array';
  23. // ------------------------------------
  24. print "<BR/>";
  25. // ------------------------------------
  26. foreach ( $_GET as $key => $value ) {
  27.  print $key . " " . "=" . " " . $value;
  28.  print "<BR/>";
  29. }
  30. // ------------------------------------
  31. print "<BR/>";
  32. // ------------------------------------
  33. print "<BR/>";
  34. // ------------------------------------
  35. print '$_REQUEST array';
  36. // ------------------------------------
  37. print "<BR/>";
  38. // ------------------------------------
  39. foreach ( $_REQUEST as $key => $value ) {
  40.  print $key . " " . "=" . " " . $value;
  41.  print "<BR/>";
  42. }
  43. echo '<p>';
  44. echo '<p>';
  45.  
  46.  
  47. echo '<strong>'.'<p>'. 'the $ts variable holds the value: '. $ts.'<p>'.'</strong>';
  48.  
  49. $stamp = "select * from events where STAMP < '$ts' ";
  50. $result = odbc_exec($connect,$stamp);
  51.  
  52.  
  53.     for($f=1;$f<=odbc_num_fields($result);$f++) 
  54.     {
  55.  
  56.         echo "'<p>'.<td style=\"font-weight:bold\">$f ". odbc_field_name($result,$f);
  57.  
  58.     }
  59.  
  60.     echo '<p>';
  61. if (odbc_next_result($result))
  62.     {
  63.         echo 'hello again';
  64.         while ($rs = odbc_fetch_array($result))
  65.             {
  66.                 echo $rs. ' this is $rs';
  67.                 $disp=odbc_result($rs,"STAMP");
  68.                 echo "<td><p>$disp</td></tr>";
  69.             }
  70.     }
  71.  
  72.     if(odbc_num_rows($result))
  73.     {
  74.  
  75.         echo ' there are matching records';
  76.     }
  77.     else
  78.     {
  79.         echo ' no matching records';
  80.     }
  81.  
  82.     echo '<strong>'.'<p>'. 'the $result variable holds the value: '. $result .'<p>'.'</strong>';
  83.  
  84. odbc_close($connect);
  85. echo "</table>";
  86. ?>
i suppose that the fact that the if statement( odbc_next_result ) and the cosequent while loop is not being enetered at all, may be a big part of the problem.
i thought that perhaps there was a problem with my date format from my calendar but even when i change the mssql query with data (from the stamp field) from the events table, still that loop is not entered and data is not thrown out onto the screen.
e.g.select * from events where stamp <'2008-02-05 16:59:13.170';
when this is run in mssql management studio, i get alot of results.

the $result variable holds the value:resource ID#4. so that says that data is coming through succesfully. and i get the statement: ' there are matching records'; and i also can get the odbc_field_name to retun the correct field names. which are listed out on my web page.

my GET and REQUEST arrays hold the data selected that was selected by the user via the calendar and posted through.
so i am so stuck, im on the verge of jumping off a bridge. and i have to get this done asap!

i do apologise if i am repeating myself.(really sorry!) but i honestly, dont know what else to do.

thankyou very much for your time and effort.and thanks for the rather quick reply.
i had another problem with mysql and php, called \ Issue with triggers, if statement,and count(); its rather urgent \ but i recieved no responsed, so this reply is a relief to say the very least.

that is not so urgent anymore.(its been 27 days! lol.)
thanks again. :{
imran
Feb 27 '08 #3
Markus
6,050 Expert 4TB
In the while loop, $rs becomes an array of your table, so there is no need to use odbc_result.
Try this instead:
[php]
while($_rs = odbc_fetch_array($_result)
{
echo $_rs['STAMP'] . " <br /> \n";
}
[/php]

Hope this helps and sorry if i missed the problem.
Feb 27 '08 #4
2DIL
6
In the while loop, $rs becomes an array of your table, so there is no need to use odbc_result.
Try this instead:
[php]
while($_rs = odbc_fetch_array($_result)
{
echo $_rs['STAMP'] . " <br /> \n";
}
[/php]

Hope this helps and sorry if i missed the problem.

Unfortunately, that has not made any difference, and still no results are being displayed, i tried both while($_rs = odbc_fetch_array($_result) and while($_rs = odbc_fetch_array($result) - because $result, is actually my variable name...

im really scared incase it is not simply a coding problem,and perhaps something else, becasue, like i say, with the code i have - i have no errors, yet i cannot display the results.....

if worst comes to worst,then would it be possible if someone could set up a similar solution, themselves - ( i could send you the calendar page) if anyone required, and possibly try to work a solution and an mssql database?
again i could send you the required info.

but perhaps this is the final call!

ive worked on this now for at least a month, getting as far as ihave an then getting no where..

i want to say thankyou for the quick responses i am recieving, to everyone who has even glanced at my problem.

Thanks once again - but please keep the answers coming.
imran
Feb 27 '08 #5
ronverdonk
4,258 Expert 4TB
Could you tell what this statement results in
[php]if (odbc_next_result($result))[/php]
I bet it is false because there is no second result set for your query.
According to the php doc on odbc_next_result, you have to refer to the mssql_next_result command for a good description. So I did and that states:
When sending more than one SQL statement to the server or executing a stored procedure with multiple results, it will cause the server to return multiple result sets. This function will test for additional results available form the server. If an additional result set exists it will free the existing result set and prepare to fetch the rows from the new result set.
You have not more than 1 SELECT statement, so the odbc_next_result is useless.

I guess that the odbc_next_result frees your result set and, since there is no result set left, returns a FALSE condition. Hence the 'no matching records'.

My suggestion is to take command odbc_next_result out.

Ronald
Feb 27 '08 #6
2DIL
6
Could you tell what this statement results in
[php]if (odbc_next_result($result))[/php]
I bet it is false because there is no second result set for your query.
According to the php doc on odbc_next_result, you have to refer to the mssql_next_result command for a good description. So I did and that states:
You have not more than 1 SELECT statement, so the odbc_next_result is useless.

I guess that the odbc_next_result frees your result set and, since there is no result set left, returns a FALSE condition. Hence the 'no matching records'.

My suggestion is to take command odbc_next_result out.

Ronald

0h Man,
youre a saviour, i have just woken up and so i dont have the energy to scream in delight, but do come round, and ill get u lunch or something.lol.( i wish i could)

you lot just saved my ass!
thanks so so so so so much
imran
Feb 28 '08 #7
ronverdonk
4,258 Expert 4TB
0h Man,
youre a saviour, i have just woken up and so i dont have the energy to scream in delight, but do come round, and ill get u lunch or something.lol.( i wish i could)

you lot just saved my ass!
thanks so so so so so much
imran
As always, you are welcome. I am glad you are out of the pit. See you next time.

Ronald
Feb 28 '08 #8
2DIL
6
thankyou so much my friend.
you have savd me a bleep load of hassle.

btw, how do u feel when u sort out a solution for someone??
imran
Feb 28 '08 #9
ronverdonk
4,258 Expert 4TB
thankyou so much my friend.
you have savd me a bleep load of hassle.

btw, how do u feel when u sort out a solution for someone??
imran
Like I usually feel: content.

Ronald
Feb 28 '08 #10

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

Similar topics

0
by: Cary | last post by:
Trying to install on SuSE 8.2 from source. ../configure --with-apxs=/usr/local/apache/bin/apxs --with-mysql --with-unixODBC=/usr/lib getting this error: /root/php-4.3.2/ext/odbc/php_odbc.c -o...
1
by: ishabir | last post by:
I have quite a few Oracle linked tables into my Access(97) database. But when you want to open a table get a pop window to enter Username, Password and Server. What I am trying to do is put some...
4
by: ron | last post by:
Hi, I have class object that i serialize using the System.Xml.Serialization class. Intermittently the object is not getting serialized correctly, using System.Xml.Serialization classes....
1
by: GPBSOFT | last post by:
I am Italian developer, escuse me for my bad English I have a problem with ODBC. I must link to a database from Visual FoxPro, I have installed Windows XP Professional with service pack 2. When I...
3
by: Giuseppe D'Elia | last post by:
Hi there, I got a problem using an MS Access database through ASP.NET. After updating my system from .NET Framework 1.0 to 1.1, my existing application gives me the following error when...
2
by: Ricardo Magalhães | last post by:
Hi, I using this code, to connect with a paradox file with ASP.NET. The first time its connect ok, but others times occurs the error: "ERROR - no error information available" I close all...
3
by: Zeya | last post by:
I am writing a C# program that uses MySQL as database and MySQL ODBC 3.51 driver. It works fine all the way except this scenario that needs to be addressed. 1. Get a set of records to process...
4
by: Szymon Dembek | last post by:
Hi Recently I did some DB2 and ODBC coding in Visual FoxPro. I bumped on a problem I cannot resolve. When I issue a delete statement that deletes no rows (no rows qualify for the WHERE...
1
by: ravi chandra | last post by:
Dear all , I am getting the following error while connecting from any one of my client,s CONTROL CENTER (if I am cataloging from command prompt there is no error) to db2 server SQL30081N ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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...

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.