More: What's returned from $sth-execute(); ?

2003-01-13 Thread Jeff Snoxell
Hi,

I see your point re:

Some code to illustrate:

printf Query: %s\n, $query;
my $sth = $dbh-prepare ($query);
$sth-execute();
# metadata information becomes available at this point ...
printf NUM_OF_FIELDS: %d\n, $sth-{NUM_OF_FIELDS};
print Note: query has no result set\n if $sth-{NUM_OF_FIELDS} == 0;

but what I really want to do is determine at an early stage if I have any 
results at all in my result set. Actual reason for this is that I'm doing a 
SELECT WHERE query and scanning my entrire DB  for a session ID that 
matches one read from a cookie. I then want to determine if this is a valid 
session id and if not re-direct the user to a page saying unrecongnised 
session id or something.

Thanks,


Jeff 


-
Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



What's returned from $sth-execute(); ?

2003-01-10 Thread Jeff Snoxell
Hi,

I've been using the return value of $sth-execute(); (in Perl DBI) to
determine if I have a result set. I'm not using the value I get back but am
assuming that if it's =1 then I have some results.

Is this a safe thing to do with MySQL?

And

The results do actually seem to be correct for the number of records I get
back. Should this be the case? Is it reliable?

Thanks,


Jeff


-
Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: What's returned from $sth-execute(); ?

2003-01-10 Thread Paul DuBois
At 16:15 + 1/10/03, Jeff Snoxell wrote:

Hi,

I've been using the return value of $sth-execute(); (in Perl DBI) to
determine if I have a result set. I'm not using the value I get back but am
assuming that if it's =1 then I have some results.


That's incorrect because it's valid for a result set to be empty (have
zero rows).  Consider the result of SELECT * FROM t WHERE 1 = 0.


You don't need to use the return value at all.  Check the metadata to
see if the number of columns is zero.  If it is, there's no result set.
If it's  0, there is a result set.

Some code to illustrate:

printf Query: %s\n, $query;
my $sth = $dbh-prepare ($query);
$sth-execute();
# metadata information becomes available at this point ...
printf NUM_OF_FIELDS: %d\n, $sth-{NUM_OF_FIELDS};
print Note: query has no result set\n if $sth-{NUM_OF_FIELDS} == 0;




Is this a safe thing to do with MySQL?

And

The results do actually seem to be correct for the number of records I get
back. Should this be the case? Is it reliable?


If you mean, can you interpret the $sth-execute() result as a row
count, the DBI docs specifically discourage it.



Thanks,

Jeff



-
Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: What's returned from $sth-execute(); ?

2003-01-10 Thread Rich Allen
this should answer  your question, from the DBI documentation

http://search.cpan.org/author/TIMB/DBI-1.30/DBI.pm#execute

sql,query,queries,smallint

- hcir
On Friday, January 10, 2003, at 02:55 PM, [EMAIL PROTECTED] wrote:


I've been using the return value of $sth-execute(); (in Perl DBI) to
determine if I have a result set. I'm not using the value I get back
but am
assuming that if it's =1 then I have some results.



-
Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php