List:General Discussion« Previous MessageNext Message »
From:fbsd_user Date:March 13 2006 2:57pm
Subject:RE: Checking for good update
View as plain text  
Thank you Michael.  I learned a lot from your detailed explanation
of how the update and select functions work in relation to
checking for good execution.

I used
if (mysql_affected_rows() == 1)
and got the results I was after.

I am stilling having problem with users browser
caching the screen, but will post that as separate question.

Again thanks for your expert help.



-----Original Message-----
From: Michael Stassen [mailto:Michael.Stassen@stripped]
Sent: Monday, March 13, 2006 4:18 AM
To: mysql@stripped
Cc: mysql@stripped
Subject: Re: Checking for good update


mysql@stripped wrote:
> On Sun, 12 Mar 2006, Michael Stassen wrote:
>>
>>mysql@stripped 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/mysql?unsub=1

Thread
Checking for good updatefbsd_user12 Mar
  • Re: Checking for good updatemysql12 Mar
    • Re: Checking for good updatemysql12 Mar
      • RE: Checking for good updatefbsd_user13 Mar
        • Re: Checking for good updateMichael Stassen13 Mar
    • Re: Checking for good updateMichael Stassen13 Mar
      • Re: Checking for good updatemysql13 Mar
        • Re: Checking for good updateMichael Stassen13 Mar
          • Re: Checking for good updatemysql13 Mar
          • RE: Checking for good updatefbsd_user13 Mar
RE: Checking for good updateSST - Adelaide)12 Mar
  • RE: Checking for good updatefbsd_user12 Mar