Re: [PHP] Best way to figure out whether a query returns RESULT or NON-RESULT

2004-10-16 Thread Chris
Karam Chand wrote:
Hello,
I have an app where one module is similar to
phpMyAdmin (well only .1%) with error_reporting() set
to E_ALL.
Now a user can execute any query. What is the best way
to know whether a query is result or non-result.
e.g.
 

. . .
Thanks in advance 

Regards,
Karam
 

As it states on http://www.php.net/mysql_query :
 Only for SELECT,SHOW,EXPLAIN or DESCRIBE statements *mysql_query()* 
returns a resource identifier or *FALSE* if the query was not executed 
correctly. For other type of SQL statements, *mysql_query()* returns 
*TRUE* on success and *FALSE* on error. A non-*FALSE* return value means 
that the query was legal and could be executed by the server.

So ,  (false !== $result) means the query was sucessful , and if it was 
successful (true === $result) would mean that no rows were returned.

Chris
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Best way to figure out whether a query returns RESULT or NON-RESULT

2004-10-16 Thread Karam Chand
Hello,

mysql_query() returns non-false even if there was an
UPDATE statement and the query was successful.

But if I put the $result variable in mysql_num_rows()
it returns an error, $result in invalid handle. 

I was asking how to know that where its an UPDATE
statement so I dont call mysql_num_rows() at all.

The problem is that if I set error_reporting( 0 ),
everything works but we are required to have
error_reporting ( E_ALL )

Regards,
Karam



--- Chris [EMAIL PROTECTED] wrote:

 Karam Chand wrote:
 
 Hello,
 
 I have an app where one module is similar to
 phpMyAdmin (well only .1%) with error_reporting()
 set
 to E_ALL.
 
 Now a user can execute any query. What is the best
 way
 to know whether a query is result or non-result.
 
 e.g.
 
   
 
 . . .
 
 Thanks in advance 
 
 Regards,
 Karam
 
   
 
 
 As it states on http://www.php.net/mysql_query :
 
  Only for SELECT,SHOW,EXPLAIN or DESCRIBE
 statements *mysql_query()* 
 returns a resource identifier or *FALSE* if the
 query was not executed 
 correctly. For other type of SQL statements,
 *mysql_query()* returns 
 *TRUE* on success and *FALSE* on error. A
 non-*FALSE* return value means 
 that the query was legal and could be executed by
 the server.
 
 So ,  (false !== $result) means the query was
 sucessful , and if it was 
 successful (true === $result) would mean that no
 rows were returned.
 
 Chris
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Best way to figure out whether a query returns RESULT or NON-RESULT

2004-10-16 Thread Marek Kilimajer
Karam Chand wrote:
Hello,
mysql_query() returns non-false even if there was an
UPDATE statement and the query was successful.
But if I put the $result variable in mysql_num_rows()
it returns an error, $result in invalid handle. 

I was asking how to know that where its an UPDATE
statement so I dont call mysql_num_rows() at all.
I Chris said, if($result === true || $result === false), no rows were 
returned.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Best way to figure out whether a query returns RESULT or NON-RESULT

2004-10-16 Thread Karam Chand
Thanks.

Never knew there existed (===). Silly me :)

Regards,
Karam

--- Marek Kilimajer [EMAIL PROTECTED] wrote:

 Karam Chand wrote:
  Hello,
  
  mysql_query() returns non-false even if there was
 an
  UPDATE statement and the query was successful.
  
  But if I put the $result variable in
 mysql_num_rows()
  it returns an error, $result in invalid handle. 
  
  I was asking how to know that where its an UPDATE
  statement so I dont call mysql_num_rows() at all.
 
 I Chris said, if($result === true || $result ===
 false), no rows were 
 returned.
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 




___
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Best way to figure out whether a query returns RESULT or NON-RESULT

2004-10-15 Thread Karam Chand
Hello,

I have an app where one module is similar to
phpMyAdmin (well only .1%) with error_reporting() set
to E_ALL.

Now a user can execute any query. What is the best way
to know whether a query is result or non-result.

e.g.



$result  = mysql_query ( $query, $mysql );

if ( !$result ) {
 HandleError ( mysql_errno(), mysql_error() );
 return;
}

if ( !mysql_num_rows ( $result )  !mysql_num_fields
( $result ) )
{
// handle non_result values
return;
}

// handle result values

 

The problem is that if its an Update stmt. php throws
up an error that $result in mysql_num_rows() is not a
valid handle.

Moreover, from the manual - mysql_affected_rows() does
not work with SELECT statements; only on statements
which modify records. So to use it I have to figure
out if its a non-SELECT statement  

What you PHP gurus suggest the best way to handle such
situations?

Thanks in advance 

Regards,
Karam



___
Do you Yahoo!?
Express yourself with Y! Messenger! Free. Download now. 
http://messenger.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php