By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,304 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,304 IT Pros & Developers. It's quick & easy.

PHP odbc error,with no error

P: 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
Share this Question
Share on Google+
9 Replies


ronverdonk
Expert 2.5K+
P: 4,258
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

P: 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
Expert 5K+
P: 6,050
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

P: 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
Expert 2.5K+
P: 4,258
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

P: 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
Expert 2.5K+
P: 4,258
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

P: 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
Expert 2.5K+
P: 4,258
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

Post your reply

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