> -----Original Message-----
> Sent: 18 February 2003 08:26
> If I remove the '|| die' part from the mysql_query() 
> statement, it works
> fine. This is bizarre, but there it is.
> ie, if I have:
> $result = mysql_query("SELECT * FROM SOME_TABLE");
> it works.
> If I have:
> $result = mysql_query("SELECT * FROM SOME_TABLE") || die 
> ("Unable to execute
> SQL query");
> it doesn't work. It gives me: " Supplied argument is not a valid MySQL
> result resource"

The || and OR operators, although both doing a Boolean or, have different priorities, 

  $result = mysql_query(...) or die(...);

is the same as

  ($result = mysql_query(...)) or die(...);


  $result = mysql_query(...) || die(...);

is the same as

  $result = (mysql_query(...) || die(...));

In the first case, the result of mysql_query() is assigned into $result, and if it 
returns FALSE the die() is performed.  In the second case, the result of applying the 
|| operator to the mysql_query() and the die() is assigned to $result; because PHP 
uses short-circuit evaluation, the die() is still only executed if mysql_query returns 
FALSE, but the || operator still returns a simple Boolean to be assigned to $result -- 
which, if the die() hasn't fired, must be TRUE (which PHP generally prints as 1).  QED.



Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

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

Reply via email to