Thankyou for that explanation Michael. I shall look into using that construct in my own code now!
Apologies to fbsd_user for my previous comments on his coding style. Regards Keith Roberts In theory, theory and practice are the same; In practice they are not. On Mon, 13 Mar 2006, Michael Stassen wrote: > To: [EMAIL PROTECTED] > From: Michael Stassen <[EMAIL PROTECTED]> > Subject: Re: Checking for good update > > [EMAIL PROTECTED] wrote: > > On Sun, 12 Mar 2006, Michael Stassen wrote: > > > > > > [EMAIL PROTECTED] wrote: > > > > > > > looks a bit strange to me. > > > > > > > > > $result = mysql_query($query) or die('Query couldn\'t > > > > > executed:'.mysql_error()); > > > > > > > > please try something like this: > > > > > > Why? There's nothing wrong with the above statement. > > > > I've never seen logic like that before. It looks to me like fbsd_user > > is trying to use the OR operator outside an if statement. > > > > Is the mentioned in the php manual somewhere Michael? > > > > > > I've not tested this - but it looks like you are mixing > > > > sending the > > > > mysql query and testing for the result of the query at the > > > > same time, > > > > which AFAIK is not possible. > > > > > > You should try it. It works just fine, and isn't the problem. > > > The > > > problem is that you cannot treat the result of an UPDATE as if it > > > were a > > > SELECT. > > > > Regards > > Keith Roberts > > Yes, this is documented. It's also standard practice (in perl and C as > well). > > OR is not part of an if statement, it is a logical operator. > <http://www.php.net/manual/en/language.operators.logical.php> "A or B" > has a value, true or false, depending on the values of A and of B. In > fact, if A is true, then "A or B" is certainly true, so there's no need to > look at B at all. This short-circuit evaluation, combined with the fact > that every assignment returns the assigned value > <http://www.php.net/manual/en/language.expressions.php>, makes a statement > like this possible. > > $result = mysql_query($query) or die('Query error:'.mysql_error()); > > First, the function mysql_query() is called. Its return value is assigned > to $result, *and* returned as the return value of the assignment operator > (=). Now we know A. If mysql_query succeeded, its return value (A) > evaluates as true, so the or operation must be true, so no need to look at > B. If, on the other hand, A is false (mysql_query failed), we must > evaluate B to determine the value of the "or" expression. Of course, to > determine the value of B, we have to call the referenced function, die(). > > Michael -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]